use new getFee api
This commit is contained in:
@@ -478,7 +478,7 @@ async fn get_fee(
|
||||
let fee = client.get_fee(operation);
|
||||
let mut coin = Coin {
|
||||
amount: "0".to_string(),
|
||||
denom: "upunk".to_string(),
|
||||
denom: "punk".to_string(),
|
||||
};
|
||||
for f in fee.amount {
|
||||
coin = coin + f.into();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { TCreateAccount, TSignInWithMnemonic } from '../types'
|
||||
import { Coin, Operation, TCreateAccount, TSignInWithMnemonic } from '../types'
|
||||
|
||||
export const createAccount = async (): Promise<TCreateAccount> =>
|
||||
await invoke('create_new_account')
|
||||
@@ -8,3 +8,11 @@ export const signInWithMnemonic = async (
|
||||
mnemonic: string
|
||||
): Promise<TSignInWithMnemonic> =>
|
||||
await invoke('connect_with_mnemonic', { mnemonic })
|
||||
|
||||
export const minorToMajor = async (amount: string): Promise<Coin> =>
|
||||
await invoke('minor_to_major', { amount })
|
||||
export const majorToMinor = async (amount: string): Promise<Coin> =>
|
||||
await invoke('major_to_minor', { amount })
|
||||
|
||||
export const getGasFee = async (operation: Operation): Promise<Coin> =>
|
||||
await invoke('get_fee', { operation })
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
import React, { useContext } from 'react'
|
||||
import { Card, Divider, Grid, Theme, Typography } from '@material-ui/core'
|
||||
import React, { useContext, useEffect, useState } from 'react'
|
||||
import {
|
||||
Card,
|
||||
CircularProgress,
|
||||
Divider,
|
||||
Grid,
|
||||
Theme,
|
||||
Typography,
|
||||
} from '@material-ui/core'
|
||||
import { useTheme } from '@material-ui/styles'
|
||||
import { useFormContext } from 'react-hook-form'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { getGasFee } from '../../requests'
|
||||
|
||||
export const SendReview = () => {
|
||||
const { gasPrice } = useContext(ClientContext)
|
||||
const { getValues } = useFormContext()
|
||||
const [transferFee, setTransferFee] = useState<string>()
|
||||
const [isLoadingFee, setIsLoadingFee] = useState(true)
|
||||
|
||||
const values = getValues()
|
||||
|
||||
const theme: Theme = useTheme()
|
||||
|
||||
useEffect(() => {
|
||||
const getFee = async () => {
|
||||
const fee = await getGasFee('Send')
|
||||
setTransferFee(fee.amount)
|
||||
setIsLoadingFee(false)
|
||||
}
|
||||
getFee()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Card
|
||||
variant="outlined"
|
||||
@@ -21,32 +39,36 @@ export const SendReview = () => {
|
||||
margin: theme.spacing(3, 0),
|
||||
}}
|
||||
>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="From" subtitle={values.from} />
|
||||
{isLoadingFee ? (
|
||||
<CircularProgress size={48} />
|
||||
) : (
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="From" subtitle={values.from} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="To" subtitle={values.to} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="Amount" subtitle={values.amount} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField
|
||||
title="Transfer fee"
|
||||
subtitle={transferFee + ' PUNK'}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="To" subtitle={values.to} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField title="Amount" subtitle={values.amount} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider light />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<SendReviewField
|
||||
title="Transfer fee"
|
||||
subtitle={gasPrice?.amount + ' PUNK'}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -90,13 +90,3 @@ export const validateRawPort = (rawPort: number): boolean =>
|
||||
|
||||
export const truncate = (text: string, trim: number) =>
|
||||
text.substring(0, trim) + '...'
|
||||
|
||||
// export const getDisplaySendGasFee = async (): Promise<string> => {
|
||||
// const nymGasFee: any = await invoke('get_gas_price')
|
||||
// const nymGasLimit: any = await invoke('get_gas_limits')
|
||||
|
||||
// const table = buildFeeTable(nymGasFee, nymGasLimit, nymGasLimit)
|
||||
|
||||
// console.log({ nymGasFee, nymGasLimit })
|
||||
// return 'coin'
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user