Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JA-71-Provide initial data needed for the client #72

Open
wants to merge 3 commits into
base: jelly-swap
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/appConfig/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default class AppConfigRepository {
return this.appConfigRepository.save({});
}

async updateConfig(id, newConfig) {
const prop = Object.keys(newConfig)[0];
async updateConfig(newConfig) {
const config = await this.getConfig();

await this.appConfigRepository.update(id, { [prop]: newConfig[prop] });
await this.appConfigRepository.update(config.id, newConfig);

return this.getConfig();
}
Expand Down
4 changes: 1 addition & 3 deletions src/components/appConfig/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export class AppConfigService {
}

async updateConfig(newConfig) {
const { id, ...rest } = newConfig;

return this.appConfig.updateConfig(id, rest);
return this.appConfig.updateConfig(newConfig);
}
}
4 changes: 4 additions & 0 deletions src/components/pending/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export default class PendingRepository {
public findManyByIds(ids) {
return this.pendingRepository.find({ where: { id: In(ids) } });
}

public getAll() {
return this.pendingRepository.find();
}
}
4 changes: 4 additions & 0 deletions src/components/refund/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export default class RefundRepository {
public findManyByIds(ids) {
return this.refundRepository.find({ where: { id: In(ids) } });
}

public getAll() {
return this.refundRepository.find();
}
}
4 changes: 4 additions & 0 deletions src/components/withdraw/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export default class WithdrawRepository {
public findManyByIds(ids: string[]) {
return this.withdrawRepository.find({ where: { id: In(ids) } });
}

public getAll() {
return this.withdrawRepository.find();
}
}
10 changes: 1 addition & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import { run } from './run';

const config = process.argv[2];
const combinedFile = process.argv[3];
const errorFile = process.argv[4];

// Electron fork
if (config) {
run(JSON.parse(config), combinedFile, errorFile);
} else {
run();
}
run();
22 changes: 22 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import UserConfig from './config';
import { PK_MATCH_ADDRESS, compareAddress } from './blockchain/utils';
import { SECONDARY_NETWORKS } from './blockchain/erc20/config';

import AppConfigRepository from './components/appConfig/repository';
import WithdrawRepository from './components/withdraw/repository';
import RefundRepository from './components/refund/repository';
import PendingRepository from './components/pending/repository';

/*
TODO: EXECUTE THESE WHEN BUTLER IS STARTED => {
create end point and execute these when end point is called from the client
Expand Down Expand Up @@ -57,6 +62,23 @@ export const run = (config = userConfig, combinedFile?: string, errorFile?: stri
.then(async () => {
await createServer(config.SERVER.PORT);

const [appConfig, pendingSwaps, pastWithdraws, pastRefunds] = await Promise.all([
new AppConfigRepository().getConfig(),
new PendingRepository().getAll(),
new WithdrawRepository().getAll(),
new RefundRepository().getAll(),
]);

if (typeof process.send === 'function') {
process.send({
topic: 'initialData',
appConfig,
pendingSwaps,
pastWithdraws,
pastRefunds,
});
}

getContracts();
})
.catch((error) => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true
"esModuleInterop": true,
"sourceMap": true
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4798,9 +4798,9 @@ y18n@^4.0.0:
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==

y18n@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.1.tgz#1ad2a7eddfa8bce7caa2e1f6b5da96c39d99d571"
integrity sha512-/jJ831jEs4vGDbYPQp4yGKDYPSCCEQ45uZWJHE1AoYBzqdZi8+LDWas0z4HrmJXmKdpFsTiowSHXdxyFhpmdMg==
version "5.0.2"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.2.tgz#48218df5da2731b4403115c39a1af709c873f829"
integrity sha512-CkwaeZw6dQgqgPGeTWKMXCRmMcBgETFlTml1+ZOO+q7kGst8NREJ+eWwFNPVUQ4QGdAaklbqCZHH6Zuep1RjiA==

yaeti@^0.0.6:
version "0.0.6"
Expand Down Expand Up @@ -4830,9 +4830,9 @@ yargs-parser@^18.1.2:
decamelize "^1.2.0"

yargs-parser@^20.0.0:
version "20.2.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.0.tgz#944791ca2be2e08ddadd3d87e9de4c6484338605"
integrity sha512-2agPoRFPoIcFzOIp6656gcvsg2ohtscpw2OINr/q46+Sq41xz2OYLqx5HRHabmFU1OARIPAYH5uteICE7mn/5A==
version "20.2.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.1.tgz#28f3773c546cdd8a69ddae68116b48a5da328e77"
integrity sha512-yYsjuSkjbLMBp16eaOt7/siKTjNVjMm3SoJnIg3sEh/JsvqVVDyjRKmaJV4cl+lNIgq6QEco2i3gDebJl7/vLA==

yargs@^15.0.0:
version "15.4.1"
Expand Down