diff --git a/.changeset/tough-boxes-flash.md b/.changeset/tough-boxes-flash.md new file mode 100644 index 000000000000..85a24d45d2e4 --- /dev/null +++ b/.changeset/tough-boxes-flash.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/coin-polkadot": minor +--- + +Update lockedbalance retrieval polkadot diff --git a/libs/coin-polkadot/src/api/sidecar.ts b/libs/coin-polkadot/src/api/sidecar.ts index 6d55dd5cb4c5..756f7cd0f35f 100644 --- a/libs/coin-polkadot/src/api/sidecar.ts +++ b/libs/coin-polkadot/src/api/sidecar.ts @@ -419,7 +419,7 @@ const getBalances = (network: NetworkRequestCall) => async (addr: string) => { balance, spendableBalance, nonce: Number(balanceInfo.nonce), - lockedBalance: new BigNumber(balanceInfo.miscFrozen), + lockedBalance: new BigNumber(totalLocked), }; }; diff --git a/libs/coin-polkadot/src/api/sidecar.unit.test.ts b/libs/coin-polkadot/src/api/sidecar.unit.test.ts new file mode 100644 index 000000000000..fa21b7799275 --- /dev/null +++ b/libs/coin-polkadot/src/api/sidecar.unit.test.ts @@ -0,0 +1,48 @@ +import BigNumber from "bignumber.js"; +import { getAccount } from "./sidecar"; + +const networkApiMock = jest.fn(); + +describe("getAccount", () => { + it("should estimate lockedBalance correctly with 1 locked balance type", async () => { + const lockedBalanceFn = getAccount(networkApiMock, jest.fn()); + networkApiMock.mockResolvedValue({ + data: { + locks: [ + { + amount: "60000000000", + reasons: "All", + }, + ], + targets: [], + }, + }); + const { lockedBalance } = await lockedBalanceFn("addr"); + expect(lockedBalance).toEqual(new BigNumber("60000000000")); + }); + + it("should estimate lockedBalance when one locked balance is higher than others", async () => { + const lockedBalanceFn = getAccount(networkApiMock, jest.fn()); + networkApiMock.mockResolvedValue({ + data: { + locks: [ + { + amount: "1", + reasons: "reason 1", + }, + { + amount: "5", + reasons: "reason 2", + }, + { + amount: "3", + reasons: "reason 3", + }, + ], + targets: [], + }, + }); + const { lockedBalance } = await lockedBalanceFn("addr"); + expect(lockedBalance).toEqual(new BigNumber("5")); + }); +});