Skip to content

Commit

Permalink
Merge pull request #204 from forbole/fix/rewards-divisor
Browse files Browse the repository at this point in the history
fix: rewards divisor
  • Loading branch information
icfor authored Apr 5, 2024
2 parents f12fdbe + 8f41437 commit fe80b91
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
15 changes: 2 additions & 13 deletions src/screens/staking/lib/staking_sdk/staking_client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import BigNumber from "bignumber.js";

import type { StakingNetworkId } from "./core/base";
import { cosmosStakingNetworks } from "./core/cosmos";
import type {
AccountDetailResponse,
ClaimableRewardsResponse,
StakingInfoResponse,
} from "./staking_client_types";
import { normaliseCoin, unnormalisedDenomToNetwork } from "./utils/coins";
import { normaliseCoin } from "./utils/coins";

const baseUrl =
process.env.NEXT_PUBLIC_STAKING_API || "https://staking-api.forbole.com";
Expand All @@ -29,22 +28,12 @@ const fetchJson = <A = any>(uri: string, opts?: Options): Promise<A> =>
},
}).then((res) => res.json());

const getRewardsDivisor = (denom: string) => {
const network = unnormalisedDenomToNetwork[denom.toUpperCase()];

if (cosmosStakingNetworks.has(network as StakingNetworkId)) {
return new BigNumber(10).pow(18);
}

return 1;
};

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

return {
...reward,
Expand Down
11 changes: 0 additions & 11 deletions src/screens/staking/lib/staking_sdk/utils/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ export const networkToUnnormalisedDenom = {

type DenomToNormalise = (typeof networkToUnnormalisedDenom)[StakingNetworkId];

export const unnormalisedDenomToNetwork = Object.entries(
networkToUnnormalisedDenom,
).reduce(
(acc, [k, v]) => {
acc[v] = k as StakingNetworkId;

return acc;
},
{} as Record<string, StakingNetworkId>,
);

const aExp = 18;
const pExp = 12;
const uExp = 6;
Expand Down

0 comments on commit fe80b91

Please sign in to comment.