Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bc513d53d | |||
| 76a8e05478 | |||
| 65e42cfc52 | |||
| 6380027afd |
@@ -1,6 +1,7 @@
|
||||
VALIDATOR_ADDRESS=
|
||||
MNEMONIC=
|
||||
TESTNET_URL_1=
|
||||
TESTNET_URL_2=
|
||||
MAJOR_CURRENCY=nymt
|
||||
MINOR_CURRENCY=unymt
|
||||
ACCOUNT_ADDRESS=
|
||||
|
||||
NETWORK=sandbox
|
||||
MNEMONIC=""
|
||||
TESTNET_URL=https://sandbox-validator.nymtech.net
|
||||
VALIDATOR_CONTRACT=
|
||||
@@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
.parcel-cache
|
||||
.env
|
||||
@@ -8,6 +8,9 @@ import {
|
||||
} from '@mui/material'
|
||||
import RefreshIcon from '@mui/icons-material/Refresh'
|
||||
import { GlobalContext, EnumRequestType } from '../context'
|
||||
import { config } from '../config'
|
||||
|
||||
export const { MAJOR_CURRENCY } = config
|
||||
|
||||
export const Balance = () => {
|
||||
const { balance, loadingState, getBalance } = useContext(GlobalContext)
|
||||
@@ -27,9 +30,9 @@ export const Balance = () => {
|
||||
<Typography
|
||||
component="span"
|
||||
variant="h6"
|
||||
data-testid="punk-balance-message"
|
||||
data-testid="balance-message"
|
||||
>
|
||||
{balance} PUNKS
|
||||
{balance} {MAJOR_CURRENCY}
|
||||
</Typography>
|
||||
</Typography>
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { getCoinValue } from '../../utils'
|
||||
import { EnumRequestType, GlobalContext } from '../../context'
|
||||
import { TokenTransfer } from '../token-transfer'
|
||||
|
||||
|
||||
type TFormData = {
|
||||
address: string
|
||||
amount: string
|
||||
@@ -35,11 +36,11 @@ export const Form = () => {
|
||||
useContext(GlobalContext)
|
||||
|
||||
const onSubmit: SubmitHandler<TFormData> = async (data) => {
|
||||
const upunks = getCoinValue(data.amount)
|
||||
const minorcurrency = getCoinValue(data.amount)
|
||||
await requestTokens({
|
||||
address: data.address,
|
||||
upunks: upunks.toString(),
|
||||
punks: data.amount,
|
||||
minorcurrency: minorcurrency.toString(),
|
||||
majorcurrency: data.amount,
|
||||
})
|
||||
resetForm()
|
||||
}
|
||||
@@ -61,13 +62,13 @@ export const Form = () => {
|
||||
data-testid="address"
|
||||
/>
|
||||
<TextField
|
||||
label="Amount (PUNKS)"
|
||||
label="Amount (tokens)"
|
||||
fullWidth
|
||||
{...register('amount')}
|
||||
sx={{ mb: 1 }}
|
||||
helperText={errors?.amount?.message}
|
||||
error={!!errors.amount}
|
||||
data-testid={'punk-amounts'}
|
||||
data-testid={'token-amounts'}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Card, CardHeader, Link, Typography } from '@mui/material'
|
||||
import { urls } from '../context/index'
|
||||
import { config } from '../config'
|
||||
|
||||
export const { MAJOR_CURRENCY } = config
|
||||
|
||||
|
||||
export const TokenTransfer = ({
|
||||
address,
|
||||
@@ -21,7 +25,7 @@ export const TokenTransfer = ({
|
||||
title={
|
||||
<>
|
||||
<Typography component="span" variant="h5">
|
||||
Successfully transferred {amount} PUNKS to
|
||||
Successfully transferred {amount} {MAJOR_CURRENCY} to
|
||||
</Typography>{' '}
|
||||
<Link
|
||||
target="_blank"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export const config = {
|
||||
MAJOR_CURRENCY: process.env.MAJOR_CURRENCY,
|
||||
MINOR_CURRENCY: process.env.MINOR_CURRENCY,
|
||||
ACCOUNT_ADDRESS: process.env.ACCOUNT_ADDRESS,
|
||||
NETWORK: process.env.NETWORK,
|
||||
MNEMONIC: process.env.MNEMONIC,
|
||||
TESTNET_URL: process.env.TESTNET_URL,
|
||||
VALIDATOR_ADDRESS: process.env.VALIDATOR_CONTRACT
|
||||
}
|
||||
@@ -2,20 +2,23 @@ import { createContext, useEffect, useState } from 'react'
|
||||
import ClientValidator, {
|
||||
nativeToPrintable,
|
||||
} from '@nymproject/nym-validator-client'
|
||||
import { config } from '../config'
|
||||
|
||||
export const { MAJOR_CURRENCY, MINOR_CURRENCY, VALIDATOR_ADDRESS, ACCOUNT_ADDRESS, NETWORK , TESTNET_URL, MNEMONIC } = config
|
||||
|
||||
export const urls = {
|
||||
blockExplorer: 'https://testnet-milhon-blocks.nymtech.net',
|
||||
blockExplorer: `https://${NETWORK}-blocks.nymtech.net`,
|
||||
}
|
||||
|
||||
type TGlobalContext = {
|
||||
getBalance: () => void
|
||||
requestTokens: ({
|
||||
address,
|
||||
upunks,
|
||||
minorcurrency,
|
||||
}: {
|
||||
address: string
|
||||
upunks: string
|
||||
punks: string
|
||||
minorcurrency: string
|
||||
majorcurrency: string
|
||||
}) => void
|
||||
loadingState: TLoadingState
|
||||
balance?: string
|
||||
@@ -25,8 +28,6 @@ type TGlobalContext = {
|
||||
|
||||
export const GlobalContext = createContext({} as TGlobalContext)
|
||||
|
||||
const { VALIDATOR_ADDRESS, MNEMONIC, TESTNET_URL_1, ACCOUNT_ADDRESS } = process.env
|
||||
|
||||
export enum EnumRequestType {
|
||||
balance = 'balance',
|
||||
tokens = 'tokens',
|
||||
@@ -52,8 +53,8 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
const Validator = await ClientValidator.connect(
|
||||
VALIDATOR_ADDRESS,
|
||||
MNEMONIC,
|
||||
[TESTNET_URL_1],
|
||||
'punk'
|
||||
[TESTNET_URL],
|
||||
MAJOR_CURRENCY
|
||||
)
|
||||
setValidator(Validator)
|
||||
}
|
||||
@@ -87,20 +88,20 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
|
||||
const requestTokens = async ({
|
||||
address,
|
||||
upunks,
|
||||
punks,
|
||||
minorcurrency,
|
||||
majorcurrency,
|
||||
}: {
|
||||
address: string
|
||||
upunks: string
|
||||
punks: string
|
||||
minorcurrency: string
|
||||
majorcurrency: string
|
||||
}) => {
|
||||
setTokenTransfer(undefined)
|
||||
setLoadingState({ isLoading: true, requestType: EnumRequestType.tokens })
|
||||
try {
|
||||
await validator?.send(ACCOUNT_ADDRESS, address, [
|
||||
{ amount: upunks, denom: 'upunk' },
|
||||
{ amount: minorcurrency, denom: MINOR_CURRENCY},
|
||||
])
|
||||
setTokenTransfer({ address, amount: punks })
|
||||
setTokenTransfer({ address, amount: majorcurrency })
|
||||
} catch (e) {
|
||||
setError(`An error occured during the transfer request: ${e}`)
|
||||
} finally {
|
||||
|
||||
Vendored
+5
-3
@@ -6,11 +6,13 @@ declare module '*.svg' {
|
||||
namespace NodeJS {
|
||||
export interface Process {
|
||||
env: {
|
||||
VALIDATOR_ADDRESS: string
|
||||
VALIDATOR_CONTRACT: string
|
||||
MNEMONIC: string
|
||||
TESTNET_URL_1: string
|
||||
TESTNET_URL_2: string
|
||||
TESTNET_URL: string
|
||||
ACCOUNT_ADDRESS: string
|
||||
MAJOR_CURRENCY: string
|
||||
MINOR_CURRENCY: string
|
||||
NETWORK: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user