Skip to content

Commit

Permalink
Latest staking rewards is now ready to go
Browse files Browse the repository at this point in the history
  • Loading branch information
isunaslabs committed Jan 12, 2023
1 parent 94040ff commit 2d2dc79
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/app-config/src/chains/testNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const testNet: ChainConfig = {
},
chainId: 43,
substrate: {
graphQlURL: "https://subql.darwinia.network/subql-apps-crab/",
graphQlURL: "https://api.subquery.network/sq/isunaslabs/pangolin2",
wssURL: "ws://g1.dev.darwinia.network:20000",
httpsURL: "https://pangolin-rpc.darwinia.network",
},
Expand Down
6 changes: 3 additions & 3 deletions packages/app-config/src/gql.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { gql } from "@apollo/client";
export const GET_LATEST_STAKING_REWARDS = gql`
query stakingRewards($accountAddress: String!, $itemsCount: Int) {
stakingStash(id: $accountAddress) {
stakingRecord(id: $accountAddress) {
id
totalRewarded
rewardeds(first: $itemsCount, orderBy: BLOCK_TIME_DESC) {
totalReward
rewards(first: $itemsCount, orderBy: BLOCK_NUMBER_DESC) {
nodes {
id
blockTime
Expand Down
1 change: 1 addition & 0 deletions packages/app-providers/src/hooks/useLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Params {
secondsPerBlock: number | undefined;
}

/* seconds per block = 12 is the constant time given by the backend */
const useLedger = ({ apiPromise, selectedAccount, secondsPerBlock = 12 }: Params) => {
/*This is the total amount of RING and KTON that the user has invested in staking, it will be used in calculating
* the total power that he has*/
Expand Down
8 changes: 4 additions & 4 deletions packages/app-types/src/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export interface Reward {
blockTime: string;
}

export interface RewardedNode {
export interface RewardNode {
nodes: Reward[];
}

export interface StakingStash {
export interface StakingRecord {
id: string; //accountId
totalRewarded: string; //RING/PRING,etc amount in string
rewardeds: RewardedNode;
totalReward: string; //RING/PRING,etc amount in string
rewards: RewardNode;
}

export interface StakingAsset {
Expand Down
13 changes: 7 additions & 6 deletions packages/app/src/components/AccountOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import BigNumber from "bignumber.js";
import ringIcon from "../../assets/images/ring.svg";
import ktonIcon from "../../assets/images/kton.svg";
import { useStorage, useWallet } from "@darwinia/app-providers";
import { StakingStash } from "@darwinia/app-types";
import { StakingRecord } from "@darwinia/app-types";
import { prettifyNumber, toTimeAgo } from "@darwinia/app-utils";
import { useQuery } from "@apollo/client";
import { GET_LATEST_STAKING_REWARDS } from "@darwinia/app-config";
import { Spinner } from "@darwinia/ui";
import { ethers } from "ethers";

interface StakingStashQuery {
accountAddress: string;
Expand All @@ -24,9 +25,9 @@ const AccountOverview = () => {
loading: isLoadingStakingData,
data: stakingData,
error,
} = useQuery<{ stakingStash: StakingStash }, StakingStashQuery>(GET_LATEST_STAKING_REWARDS, {
} = useQuery<{ stakingRecord: StakingRecord }, StakingStashQuery>(GET_LATEST_STAKING_REWARDS, {
variables: {
accountAddress: selectedAccount ?? "",
accountAddress: ethers.utils.getAddress(selectedAccount ?? ""),
itemsCount: 3,
},
});
Expand All @@ -51,15 +52,15 @@ const AccountOverview = () => {
<div className={"flex gap-[10px] flex-col"}>
<div className={"border-b divider pb-[10px] text-14-bold"}>{t(localeKeys.latestStakingRewards)}</div>
<div className={"min-h-[92px] flex flex-col text-14-bold"}>
{!error && stakingData?.stakingStash && stakingData?.stakingStash.rewardeds.nodes.length > 0 ? (
{!error && stakingData?.stakingRecord && stakingData?.stakingRecord.rewards.nodes.length > 0 ? (
<div className={"flex flex-col gap-[10px]"}>
{stakingData.stakingStash.rewardeds.nodes.map((item) => {
{stakingData.stakingRecord.rewards.nodes.map((item) => {
return (
<div className={"flex justify-between"} key={item.id}>
<div>
{prettifyNumber({
number: BigNumber(item.amount),
precision: 9,
precision: 6,
})}{" "}
{selectedNetwork?.ring.symbol}
</div>
Expand Down

0 comments on commit 2d2dc79

Please sign in to comment.