Skip to content

Commit

Permalink
feat: update rewards response
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Mar 25, 2024
1 parent 7f3428c commit 1be9d8c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/components/icons/phantom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/screens/staking/lib/staking_sdk/context/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const getAllRewards = (
if (!rewards) return acc;

const newValue = rewards.reduce((acc2, reward) => {
const normalised = normaliseCoin(reward);
const normalised = normaliseCoin(reward.coin);

const coinPrice = state.coinsPrices[normalised.denom as CoinDenom];

Expand Down
16 changes: 9 additions & 7 deletions src/screens/staking/lib/staking_sdk/staking_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ const rewardsDivisor = new BigNumber(10).pow(18);

const parseStakingRewards = async (res: ClaimableRewardsResponse) =>
Array.isArray(res)
? res
.map((coin) => {
const num = new BigNumber(coin.amount);
? res.map((reward) => {
const { coin } = reward;
const num = new BigNumber(coin.amount);

return {
return {
...reward,
coin: normaliseCoin({
amount: num.dividedBy(rewardsDivisor).toString(),
denom: coin.denom,
};
})
.map(normaliseCoin)
}),
};
})
: res;

type StakeResponse = {
Expand Down
7 changes: 6 additions & 1 deletion src/screens/staking/lib/staking_sdk/staking_client_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ export type AccountDetailResponse = {
unbonding: Unbonding[];
};

export type ClaimableRewardsResponse = Coin[] | Record<string, never>;
type Reward = {
address: string;
coin: Coin;
};

export type ClaimableRewardsResponse = Record<string, never> | Reward[];
4 changes: 2 additions & 2 deletions src/screens/staking/lib/staking_sdk/utils/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export const sortAccounts = (a: Account, b: Account) => {
export const getClaimableRewardsForAccount = (start: Coin, account: Account) =>
(Array.isArray(account.rewards) ? account.rewards : []).reduce(
(acc2, reward) => {
if (start.denom?.toUpperCase() === reward.denom?.toUpperCase()) {
return sumCoins(acc2, reward);
if (start.denom?.toUpperCase() === reward.coin.denom?.toUpperCase()) {
return sumCoins(acc2, reward.coin);
}

return acc2;
Expand Down
2 changes: 1 addition & 1 deletion src/screens/staking/lib/wallet_info.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Translate } from "next-translate";
import type { FC } from "react";

import IconPhantom from "@src/components/icons/icon_search.svg";
import IconKeplr from "@src/components/icons/keplr.svg";
import IconLeap from "@src/components/icons/leap.svg";
import IconPhantom from "@src/components/icons/phantom.svg";
import IconSolflare from "@src/components/icons/solana_wallet.svg";

import { WalletId } from "./staking_sdk/core/base";
Expand Down

0 comments on commit 1be9d8c

Please sign in to comment.