Skip to content

Commit

Permalink
remove unstake
Browse files Browse the repository at this point in the history
  • Loading branch information
mangcanbang committed Jan 8, 2024
1 parent 3764f18 commit c993e6a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 37 deletions.
28 changes: 0 additions & 28 deletions libs/ledger-live-common/src/families/icon/api/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,3 @@ export const getDelegation = async (address, currency) => {
votingPower: new BigNumber(IconAmount.fromLoop(res?.votingPower || 0, iconUnit)),
};
};

export const getStake = async (address, currency) => {
const rpcURL = getRpcUrl(currency);
const httpProvider = new HttpProvider(rpcURL);
const iconService = new IconService(httpProvider);
const prepTx: any = new IconBuilder.CallBuilder()
.to(IISS_SCORE_ADDRESS)
.method("getStake")
.params({ address })
.build();

let res;
let unstake = new BigNumber(0);
try {
res = await iconService.call(prepTx).execute();
if (res?.unstakes) {
const unstakes = res?.unstakes;
for (const item of unstakes) {
const value = BigNumber(IconAmount.fromLoop(item.unstake || 0, iconUnit));
unstake = unstake.plus(value);
}
}
} catch (error) {
// TODO: handle show log
console.log(error);
}
return { ...res, unstake };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";

import { getAccount, getOperations } from "./api/node";
import BigNumber from "bignumber.js";
import { getDelegation, getStake } from "./api/node";
import { getDelegation } from "./api/node";
import { IconResources } from "./types";

const getAccountShape: GetAccountShape = async info => {
Expand All @@ -27,13 +27,11 @@ const getAccountShape: GetAccountShape = async info => {
const newOperations = await getOperations(accountId, address, skip, currency);
const operations = mergeOps(oldOperations, newOperations);
const delegationData = await getDelegation(address, currency);
const { unstake } = await getStake(address, currency);

const iconResources: IconResources = {
nonce: 0,
totalDelegated: delegationData.totalDelegated,
votingPower: delegationData.votingPower,
unstake,
};

return {
Expand Down
6 changes: 2 additions & 4 deletions libs/ledger-live-common/src/families/icon/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import type { IconResourcesRaw, IconResources, IconAccount, IconAccountRaw } fro
import { AccountRaw, Account } from "@ledgerhq/types-live";

export function toIconResourcesRaw(r: IconResources): IconResourcesRaw {
const { nonce, votingPower, totalDelegated, unstake } = r;
const { nonce, votingPower, totalDelegated } = r;
return {
nonce,
votingPower: votingPower.toString(),
totalDelegated: totalDelegated.toString(),
unstake: unstake.toString(),
};
}

export function fromIconResourcesRaw(r: IconResourcesRaw): IconResources {
const { nonce, votingPower, totalDelegated, unstake } = r;
const { nonce, votingPower, totalDelegated } = r;
return {
nonce,
votingPower: new BigNumber(votingPower || 0),
totalDelegated: new BigNumber(totalDelegated || 0),
unstake: new BigNumber(unstake || 0),
};
}

Expand Down
2 changes: 0 additions & 2 deletions libs/ledger-live-common/src/families/icon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type IconResources = {
nonce: number;
votingPower: string | BigNumber;
totalDelegated: string | BigNumber;
unstake: string | BigNumber;
};

/**
Expand All @@ -25,7 +24,6 @@ export type IconResourcesRaw = {
nonce: number;
votingPower: string | BigNumber;
totalDelegated: string | BigNumber;
unstake: string | BigNumber;
};

/**
Expand Down

0 comments on commit c993e6a

Please sign in to comment.