Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch unstaking tokens #218

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading