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