Skip to content

Commit

Permalink
Querying decimals instead of hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantcornholio committed Jun 7, 2024
1 parent 9e38047 commit 70b6ae9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/common/src/chaindata/queries/ChainMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ export const getDenom = async (
try {
const api = await chaindata.handler.getApi();

const chainType = await api.rpc.system.chain();
if (!chainType) {
return null;
}
const denom =
chainType.toString() == "Polkadot" ? 10000000000 : 1000000000000;
return denom;
const chainProps = await api.registry.getChainProperties();
const decimals = chainProps.tokenDecimals.toJSON()[0];

return 10 ** decimals;
} catch (e) {
await handleError(chaindata, e, "getDenom", HandlerType.RelayHandler);
return null;
Expand Down
7 changes: 7 additions & 0 deletions packages/common/test/scorekeeper/NumNominations.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ describe("autoNumNominations", () => {
}),
},
},
registry: {
getChainProperties: vi.fn().mockResolvedValue({
tokenDecimals: {
toJSON: vi.fn().mockImplementation(() => [10]),
},
}),
},
});

const relayApiHandler = new ApiHandler(KusamaEndpoints);
Expand Down

0 comments on commit 70b6ae9

Please sign in to comment.