Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit a2821be

Browse files
Merge pull request #2963 from w3f/yuri/no-denom-hardcode
Querying decimals instead of hardcode
2 parents 9e38047 + 70b6ae9 commit a2821be

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/common/src/chaindata/queries/ChainMeta.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ export const getDenom = async (
3131
try {
3232
const api = await chaindata.handler.getApi();
3333

34-
const chainType = await api.rpc.system.chain();
35-
if (!chainType) {
36-
return null;
37-
}
38-
const denom =
39-
chainType.toString() == "Polkadot" ? 10000000000 : 1000000000000;
40-
return denom;
34+
const chainProps = await api.registry.getChainProperties();
35+
const decimals = chainProps.tokenDecimals.toJSON()[0];
36+
37+
return 10 ** decimals;
4138
} catch (e) {
4239
await handleError(chaindata, e, "getDenom", HandlerType.RelayHandler);
4340
return null;

packages/common/test/scorekeeper/NumNominations.unit.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ describe("autoNumNominations", () => {
6363
}),
6464
},
6565
},
66+
registry: {
67+
getChainProperties: vi.fn().mockResolvedValue({
68+
tokenDecimals: {
69+
toJSON: vi.fn().mockImplementation(() => [10]),
70+
},
71+
}),
72+
},
6673
});
6774

6875
const relayApiHandler = new ApiHandler(KusamaEndpoints);

0 commit comments

Comments
 (0)