Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
feat(profiles): sync fees per coin (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Aug 29, 2020
1 parent 2e48a25 commit 239adf8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
24 changes: 21 additions & 3 deletions packages/platform-sdk-profiles/src/environment/coin-repository.ts
Expand Up @@ -7,15 +7,27 @@ export class CoinRepository {
readonly #dataRepository: DataRepository = new DataRepository();

public delegates(coin: string, network: string): any {
const delegates = this.#dataRepository.get(`${coin}.${network}.delegates`);
const result = this.#dataRepository.get(`${coin}.${network}.delegates`);

if (delegates === undefined) {
if (result === undefined) {
throw new Error(
`The delegates for [${coin}.${network}] have not been synchronized yet. Please call [syncDelegates] before using this method.`,
);
}

return delegates;
return result;
}

public fees(coin: string, network: string, days = 7): any {
const result = this.#dataRepository.get(`${coin}.${network}.fees.${days}`);

if (result === undefined) {
throw new Error(
`The delegates for [${coin}.${network}.fees.${days}] have not been synchronized yet. Please call [syncFees] before using this method.`,
);
}

return result;
}

public async syncDelegates(coin: string, network: string): Promise<void> {
Expand All @@ -42,4 +54,10 @@ export class CoinRepository {
result.map((delegate: Contracts.WalletData) => delegate.toObject()),
);
}

public async syncFees(coin: string, network: string, days = 7): Promise<void> {
const instance: Coins.Coin = await makeCoin(coin, network);

this.#dataRepository.set(`${coin}.${network}.fees.${days}`, await instance.fee().all(days));
}
}
Expand Up @@ -96,7 +96,6 @@ export interface ReadWriteWallet {
config(): Coins.Config;
guard(): Coins.Guard;
client(): Contracts.ClientService;
fee(): Contracts.FeeService;
identity(): Contracts.IdentityService;
ledger(): Contracts.LedgerService;
link(): Contracts.LinkService;
Expand Down
4 changes: 0 additions & 4 deletions packages/platform-sdk-profiles/src/wallets/wallet.test.ts
Expand Up @@ -114,10 +114,6 @@ it("should have a client service", () => {
expect(subject.client()).toBeObject();
});

it("should have a fee service", () => {
expect(subject.fee()).toBeObject();
});

it("should have a identity service", () => {
expect(subject.identity()).toBeObject();
});
Expand Down
4 changes: 0 additions & 4 deletions packages/platform-sdk-profiles/src/wallets/wallet.ts
Expand Up @@ -309,10 +309,6 @@ export class Wallet implements ReadWriteWallet {
return this.#coin.client();
}

public fee(): Contracts.FeeService {
return this.#coin.fee();
}

public identity(): Contracts.IdentityService {
return this.#coin.identity();
}
Expand Down

0 comments on commit 239adf8

Please sign in to comment.