update currency
This commit is contained in:
@@ -29,7 +29,7 @@ export const Balance = () => {
|
||||
variant="h6"
|
||||
data-testid="punk-balance-message"
|
||||
>
|
||||
{balance} PUNKS
|
||||
{balance} NYMT
|
||||
</Typography>
|
||||
</Typography>
|
||||
}
|
||||
|
||||
@@ -26,20 +26,18 @@ export const Form = () => {
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({ resolver: yupResolver(validationSchema) })
|
||||
|
||||
console.log(errors)
|
||||
|
||||
const { requestTokens, loadingState, tokenTransfer, error } =
|
||||
useContext(GlobalContext)
|
||||
|
||||
const onSubmit: SubmitHandler<TFormData> = async (data) => {
|
||||
const upunks = getCoinValue(data.amount)
|
||||
const nymts = getCoinValue(data.amount)
|
||||
await requestTokens({
|
||||
address: data.address,
|
||||
upunks: upunks.toString(),
|
||||
punks: data.amount,
|
||||
unymts: nymts.toString(),
|
||||
nymts: data.amount,
|
||||
})
|
||||
resetForm()
|
||||
}
|
||||
@@ -55,19 +53,21 @@ export const Form = () => {
|
||||
label="Address"
|
||||
fullWidth
|
||||
{...register('address')}
|
||||
sx={{ mb: 1 }}
|
||||
sx={{ mb: 2 }}
|
||||
helperText={errors?.address?.message}
|
||||
error={!!errors.address}
|
||||
data-testid="address"
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
<TextField
|
||||
label="Amount (PUNKS)"
|
||||
label="Amount (NYMT)"
|
||||
fullWidth
|
||||
{...register('amount')}
|
||||
sx={{ mb: 1 }}
|
||||
sx={{ mb: 2 }}
|
||||
helperText={errors?.amount?.message}
|
||||
error={!!errors.amount}
|
||||
data-testid={'punk-amounts'}
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -21,7 +21,7 @@ export const TokenTransfer = ({
|
||||
title={
|
||||
<>
|
||||
<Typography component="span" variant="h5">
|
||||
Successfully transferred {amount} PUNKS to
|
||||
Successfully transferred {amount} NYMT to
|
||||
</Typography>{' '}
|
||||
<Link
|
||||
target="_blank"
|
||||
|
||||
@@ -4,18 +4,18 @@ import ClientValidator, {
|
||||
} from '@nymproject/nym-validator-client'
|
||||
|
||||
export const urls = {
|
||||
blockExplorer: 'https://sanbox-blocks.nymtech.net',
|
||||
blockExplorer: 'https://sandbox-blocks.nymtech.net',
|
||||
}
|
||||
|
||||
type TGlobalContext = {
|
||||
getBalance: () => void
|
||||
requestTokens: ({
|
||||
address,
|
||||
upunks,
|
||||
unymts,
|
||||
}: {
|
||||
address: string
|
||||
upunks: string
|
||||
punks: string
|
||||
unymts: string
|
||||
nymts: string
|
||||
}) => void
|
||||
loadingState: TLoadingState
|
||||
balance?: string
|
||||
@@ -53,7 +53,7 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
VALIDATOR_ADDRESS,
|
||||
MNEMONIC,
|
||||
[TESTNET_URL_1],
|
||||
'punk'
|
||||
'nymt'
|
||||
)
|
||||
setValidator(Validator)
|
||||
}
|
||||
@@ -76,8 +76,8 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
setLoadingState({ isLoading: true, requestType: EnumRequestType.balance })
|
||||
try {
|
||||
const balance = await validator?.getBalance(ACCOUNT_ADDRESS)
|
||||
const punks = nativeToPrintable(balance?.amount || '')
|
||||
setBalance(punks)
|
||||
const tokens = nativeToPrintable(balance?.amount || '')
|
||||
setBalance(tokens)
|
||||
} catch (e) {
|
||||
setError(`An error occured while getting the balance: ${e}`)
|
||||
} finally {
|
||||
@@ -87,20 +87,20 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
|
||||
const requestTokens = async ({
|
||||
address,
|
||||
upunks,
|
||||
punks,
|
||||
unymts,
|
||||
nymts,
|
||||
}: {
|
||||
address: string
|
||||
upunks: string
|
||||
punks: string
|
||||
unymts: string
|
||||
nymts: string
|
||||
}) => {
|
||||
setTokenTransfer(undefined)
|
||||
setLoadingState({ isLoading: true, requestType: EnumRequestType.tokens })
|
||||
try {
|
||||
await validator?.send(ACCOUNT_ADDRESS, address, [
|
||||
{ amount: upunks, denom: 'upunk' },
|
||||
{ amount: unymts, denom: 'unymt' },
|
||||
])
|
||||
setTokenTransfer({ address, amount: punks })
|
||||
setTokenTransfer({ address, amount: nymts })
|
||||
} catch (e) {
|
||||
setError(`An error occured during the transfer request: ${e}`)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user