Skip to content

Commit

Permalink
feat: fix double unbonding
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Apr 3, 2024
1 parent c88aab5 commit 0bbd0cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
58 changes: 30 additions & 28 deletions src/screens/staking/lib/staking_sdk/context/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,42 +143,44 @@ export const getUnbondingTokensForNetwork = (
): UnbondingTokensResult => {
const accountsForNetwork = getAccountsForNetwork(state, network);

return accountsForNetwork.reduce((acc, account) => {
if (!account.info?.unbonding?.length) {
return acc;
}
return accountsForNetwork
.filter(filterUniqueAddresses())
.reduce((acc, account) => {
if (!account.info?.unbonding?.length) {
return acc;
}

const { unbonding } = account.info;
const { unbonding } = account.info;

const denom = networkToUnnormalisedDenom[account.networkId];
const denom = networkToUnnormalisedDenom[account.networkId];

return unbonding.reduce((acc2, unbondingInfo) => {
const baseCoin = acc2 ? acc2.coin : getEmptyCoin(denom);
const basePeriod = acc2 ? acc2.period : "";
return unbonding.reduce((acc2, unbondingInfo) => {
const baseCoin = acc2 ? acc2.coin : getEmptyCoin(denom);
const basePeriod = acc2 ? acc2.period : "";

const newCoin = sumCoins(baseCoin, {
amount: unbondingInfo.balance,
denom,
});
const newCoin = sumCoins(baseCoin, {
amount: unbondingInfo.balance,
denom,
});

if (!unbondingInfo.completion_time)
return {
coin: newCoin,
period: basePeriod,
};
if (!unbondingInfo.completion_time)
return {
coin: newCoin,
period: basePeriod,
};

const itemPeriod = unbondingInfo.completion_time.seconds;
const itemPeriod = unbondingInfo.completion_time.seconds;

const newPeriod = new BigNumber(basePeriod).isGreaterThan(itemPeriod)
? basePeriod
: itemPeriod;
const newPeriod = new BigNumber(basePeriod).isGreaterThan(itemPeriod)
? basePeriod
: itemPeriod;

return {
coin: newCoin,
period: newPeriod,
};
}, acc);
}, null as UnbondingTokensResult);
return {
coin: newCoin,
period: newPeriod,
};
}, acc);
}, null as UnbondingTokensResult);
};

export const getHasConnectedWallets = (state: StakingState) =>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/staking/lib/staking_sdk/core/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

export const keplrNetworks = new Set<StakingNetworkId>(
[
// StakingNetworkId.Akash,
StakingNetworkId.Akash,
// StakingNetworkId.Celestia,
// StakingNetworkId.CelestiaTestnet,
// StakingNetworkId.ComposableFinance,
Expand Down

0 comments on commit 0bbd0cb

Please sign in to comment.