Skip to content

Commit

Permalink
fetch unstaking tokens (#218)
Browse files Browse the repository at this point in the history
* fetch unstaking tokens

* Update src/pages/collators/CollatorRewards.tsx

Co-authored-by: Marcel Ebert <[email protected]>

* Update src/pages/collators/CollatorRewards.tsx

Co-authored-by: Marcel Ebert <[email protected]>

---------

Co-authored-by: Marcel Ebert <[email protected]>
  • Loading branch information
gonzamontiel and ebma authored Aug 3, 2023
1 parent ce0cab0 commit ddf06d9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/pages/collators/CollatorRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function CollatorRewards() {
const [userStaking, setUserStaking] = useState<UserStaking>();
const [claimDialogOpen, setClaimDialogOpen] = useState<boolean>(false);
const [submissionPending, setSubmissionPending] = useState(false);
const [unboarding, setUnboarding] = useState<string>('0.00');

const { api, tokenSymbol, ss58Format } = useNodeInfoState().state;
const { walletAccount } = useGlobalState();
Expand Down Expand Up @@ -45,10 +46,18 @@ function CollatorRewards() {
return '0';
}
const { data: balance } = await api.query.system.account(walletAccount?.address);
return balance.free.sub(balance.miscFrozen).toString();
setUserAvailableBalance(balance.free.sub(balance.miscFrozen).toString());
};
const fetchUnstaking = async () => {
if (!api || !walletAccount) {
return '0.00';
}
const unstakingData = await api.query.parachainStaking.unstaking(walletAccount?.address);
unstakingData.forEach((n) => setUnboarding(nativeToFormat(parseInt(n.toString()), tokenSymbol)));
};

fetchAvailableBalance().then((balance) => setUserAvailableBalance(balance));
fetchUnstaking();
fetchAvailableBalance();
}, [api, walletAccount]);

const updateRewardsExtrinsic = useMemo(() => {
Expand Down Expand Up @@ -110,7 +119,7 @@ function CollatorRewards() {
</div>
<div className="flex flex-auto place-content-end">
<button className="btn btn-secondary w-full" disabled>
0 {tokenSymbol} Unboarding
{unboarding} Unboarding
</button>
</div>
</div>
Expand Down

0 comments on commit ddf06d9

Please sign in to comment.