Skip to content

Commit

Permalink
fix dot locked balance (#3755)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedi-edelbloute committed Jun 21, 2023
1 parent e60b35b commit 895205e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tough-boxes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-polkadot": minor
---

Update lockedbalance retrieval polkadot
2 changes: 1 addition & 1 deletion libs/coin-polkadot/src/api/sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};

Expand Down
48 changes: 48 additions & 0 deletions libs/coin-polkadot/src/api/sidecar.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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"));
});
});

0 comments on commit 895205e

Please sign in to comment.