72 lines
2.2 KiB
Plaintext
72 lines
2.2 KiB
Plaintext
```ts copy filename="FormattedWalletSendTokensCode.tsx"
|
|
import React, { useState } from 'react';
|
|
import Button from '@mui/material/Button';
|
|
import Paper from '@mui/material/Paper';
|
|
import Box from '@mui/material/Box';
|
|
import Typography from '@mui/material/Typography';
|
|
import TextField from '@mui/material/TextField';
|
|
|
|
// Send tokens on Parent component
|
|
const doSendTokens = async (amount: string) => {
|
|
const memo = 'test sending tokens';
|
|
setSendingTokensLoader(true);
|
|
try {
|
|
const res = await signerCosmosWasmClient.sendTokens(
|
|
account,
|
|
recipientAddress,
|
|
[{ amount, denom: 'unym' }],
|
|
'auto',
|
|
memo,
|
|
);
|
|
setLog((prev) => [
|
|
...prev,
|
|
<div key={JSON.stringify(res, null, 2)}>
|
|
<code style={{ marginRight: '2rem' }}>{new Date().toLocaleTimeString()}</code>
|
|
<pre>{JSON.stringify(res, null, 2)}</pre>
|
|
</div>,
|
|
]);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
setSendingTokensLoader(false);
|
|
};
|
|
|
|
export const SendTokes = ({
|
|
setRecipientAddress,
|
|
doSendTokens,
|
|
sendingTokensLoader,
|
|
}: {
|
|
setRecipientAddress: (value: string) => void;
|
|
doSendTokens: (amount: string) => void;
|
|
sendingTokensLoader: boolean;
|
|
}) => {
|
|
const [tokensToSend, setTokensToSend] = useState<string>();
|
|
|
|
return (
|
|
<Paper style={{ marginTop: '1rem', padding: '1rem' }}>
|
|
<Box padding={3}>
|
|
<Typography variant="h6">Send Tokens</Typography>
|
|
<Box marginTop={3} display="flex" flexDirection="column">
|
|
<TextField
|
|
type="text"
|
|
placeholder="Recipient Address"
|
|
onChange={(e) => setRecipientAddress(e.target.value)}
|
|
size="small"
|
|
/>
|
|
<Box marginY={3} display="flex" justifyContent="space-between">
|
|
<TextField
|
|
type="text"
|
|
placeholder="Amount"
|
|
onChange={(e) => setTokensToSend(e.target.value)}
|
|
size="small"
|
|
/>
|
|
<Button variant="outlined" onClick={() => doSendTokens(amount)} disabled={sendingTokensLoader}>
|
|
{sendingTokensLoader ? 'Sending...' : 'SendTokens'}
|
|
</Button>
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
</Paper>
|
|
);
|
|
};
|
|
``` |