```ts copy filename="FormattedWalletDelegationsCode.tsx" import React from 'react'; import Button from '@mui/material/Button'; import Paper from '@mui/material/Paper'; import Box from '@mui/material/Box'; import { TableBody, TableCell, TableHead, TableRow, TextField, Typography } from '@mui/material'; import Table from '@mui/material/Table'; // Get Delegations on parent component const getDelegations = useCallback(async () => { const newDelegations = await signerClient.getDelegatorDelegations({ delegator: settings.address, }); setDelegations(newDelegations); }, [signerClient]); // Make a Delegation on parent component const doDelegate = async ({ mixId, amount }: { mixId: number; amount: number }) => { if (!signerClient) { return; } setDelegationLoader(true); try { const res = await signerClient.delegateToMixnode({ mixId }, 'auto', undefined, [ { amount: `${amount}`, denom: 'unym' }, ]); console.log('res', res); setLog((prev) => [ ...prev,
{new Date().toLocaleTimeString()}
{JSON.stringify(res, null, 2)}
, ]); } catch (error) { console.error(error); } setDelegationLoader(false); }; // Undelegate All on Parent Component const doUndelegateAll = async () => { if (!signerClient) { return; } setUndeledationLoader(true); try { // eslint-disable-next-line no-restricted-syntax for (const delegation of delegations.delegations) { // eslint-disable-next-line no-await-in-loop await signerClient.undelegateFromMixnode({ mixId: delegation.mix_id }, 'auto'); } } catch (error) { console.error(error); } setUndeledationLoader(false); }; // Withdraw Rewards on Parent Component const doWithdrawRewards = async () => { const delegatorAddress = ''; const validatorAdress = ''; const memo = 'test sending tokens'; setWithdrawLoading(true); try { const res = await signerCosmosWasmClient.withdrawRewards(delegatorAddress, validatorAdress, 'auto', memo); setLog((prev) => [ ...prev,
{new Date().toLocaleTimeString()}
{JSON.stringify(res, null, 2)}
, ]); } catch (error) { console.error(error); } setWithdrawLoading(false); }; import React, { useState } from 'react'; import Button from '@mui/material/Button'; import Paper from '@mui/material/Paper'; import Box from '@mui/material/Box'; import { TableBody, TableCell, TableHead, TableRow, TextField, Typography } from '@mui/material'; import Table from '@mui/material/Table'; export const Delegations = ({ delegations, doDelegate, delegationLoader, doUndelegateAll, undeledationLoader, doWithdrawRewards, withdrawLoading, }: { delegations: any; doDelegate: ({ mixId, amount }: { mixId: number; amount: number }) => void; delegationLoader: boolean; doUndelegateAll: () => void; undeledationLoader: boolean; doWithdrawRewards: () => void; withdrawLoading: boolean; }) => { const [delegationNodeId, setDelegationNodeId] = useState(); const [amountToBeDelegated, setAmountToBeDelegated] = useState(); return ( Delegations Make a delegation setDelegationNodeId(e.target.value)} size="small" /> setAmountToBeDelegated(e.target.value)} size="small" /> Your delegations {!delegations?.delegations?.length ? ( You do not have delegations ) : ( MixId Owner Amount Cumulative Reward Ratio {delegations?.delegations.map((delegation: any) => ( {delegation.mix_id} {delegation.owner} {delegation.amount.amount} {delegation.cumulative_reward_ratio} ))}
)}
{delegations && ( )}
); }; ```