add current vesting period
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { Balance, Coin, OriginalVestingResponse } from '../types'
|
||||
import { getVestingCoins, getVestedCoins, getLockedCoins, getSpendableCoins, getOriginalVesting } from '../requests'
|
||||
import { Balance, Coin, OriginalVestingResponse, Period } from '../types'
|
||||
import {
|
||||
getVestingCoins,
|
||||
getVestedCoins,
|
||||
getLockedCoins,
|
||||
getSpendableCoins,
|
||||
getOriginalVesting,
|
||||
getCurrentVestingPeriod,
|
||||
} from '../requests'
|
||||
|
||||
type TTokenAllocation = {
|
||||
[key in 'vesting' | 'vested' | 'locked' | 'spendable' ]: Coin['amount']
|
||||
[key in 'vesting' | 'vested' | 'locked' | 'spendable']: Coin['amount']
|
||||
}
|
||||
|
||||
export type TUseuserBalance = {
|
||||
@@ -12,6 +19,7 @@ export type TUseuserBalance = {
|
||||
balance?: Balance
|
||||
tokenAllocation?: TTokenAllocation
|
||||
originalVesting?: OriginalVestingResponse
|
||||
currentVestingPeriod?: Period
|
||||
isLoading: boolean
|
||||
fetchBalance: () => void
|
||||
clearBalance: () => void
|
||||
@@ -23,6 +31,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
const [error, setError] = useState<string>()
|
||||
const [tokenAllocation, setTokenAllocation] = useState<TTokenAllocation>()
|
||||
const [originalVesting, setOriginalVesting] = useState<OriginalVestingResponse>()
|
||||
const [currentVestingPeriod, setCurrentVestingPeriod] = useState<Period>()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const fetchBalance = useCallback(async () => {
|
||||
@@ -44,22 +53,26 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
setIsLoading(true)
|
||||
if (address) {
|
||||
try {
|
||||
const [originalVestingValue, vestingCoins, vestedCoins, lockedCoins, spendableCoins] = await Promise.all([
|
||||
getOriginalVesting(address),
|
||||
getVestingCoins(address),
|
||||
getVestedCoins(address),
|
||||
getLockedCoins(address),
|
||||
getSpendableCoins(address),
|
||||
])
|
||||
const [originalVestingValue, vestingCoins, vestedCoins, lockedCoins, spendableCoins, currentVestingPeriod] =
|
||||
await Promise.all([
|
||||
getOriginalVesting(address),
|
||||
getVestingCoins(address),
|
||||
getVestedCoins(address),
|
||||
getLockedCoins(address),
|
||||
getSpendableCoins(address),
|
||||
getCurrentVestingPeriod(address),
|
||||
])
|
||||
|
||||
setOriginalVesting(originalVestingValue)
|
||||
|
||||
setCurrentVestingPeriod(currentVestingPeriod)
|
||||
setTokenAllocation({
|
||||
vesting: vestingCoins.amount,
|
||||
vested: vestedCoins.amount,
|
||||
locked: lockedCoins.amount,
|
||||
spendable: spendableCoins.amount,
|
||||
})
|
||||
|
||||
console.log(currentVestingPeriod)
|
||||
} catch (e) {
|
||||
clearTokenAllocation()
|
||||
clearOriginalVesting()
|
||||
@@ -93,6 +106,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
balance,
|
||||
tokenAllocation,
|
||||
originalVesting,
|
||||
currentVestingPeriod,
|
||||
fetchBalance,
|
||||
clearBalance,
|
||||
fetchTokenAllocation,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useSnackbar } from 'notistack'
|
||||
import { NymCard } from '../../components'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { withdrawVestedCoins } from '../../requests'
|
||||
import { Period } from '../../types'
|
||||
|
||||
export const VestingCard = () => {
|
||||
const { userBalance, currency } = useContext(ClientContext)
|
||||
@@ -151,7 +152,8 @@ const VestingTable = () => {
|
||||
<TableCell sx={{ borderBottom: 'none' }}>
|
||||
{userBalance.tokenAllocation?.vesting || 'n/a'} {currency?.major}
|
||||
</TableCell>
|
||||
<TableCell sx={{ borderBottom: 'none' }}>{userBalance.originalVesting?.number_of_periods}</TableCell>
|
||||
<TableCell align="left" sx={{ borderBottom: 'none' }}>
|
||||
{vestingPeriod(userBalance.currentVestingPeriod, userBalance.originalVesting?.number_of_periods)}</TableCell>
|
||||
<TableCell sx={{ borderBottom: 'none' }}>
|
||||
<Box display="flex" alignItems="center" gap={1}>
|
||||
<Typography
|
||||
@@ -175,3 +177,13 @@ const VestingTable = () => {
|
||||
</TableContainer>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
const vestingPeriod = (current?:Period, original?: number ) => {
|
||||
|
||||
if (current === "After") return "Complete"
|
||||
|
||||
if (typeof current === "object" && typeof original === "number") return `${current.In + 1}/${original}`
|
||||
|
||||
return "N/A"
|
||||
}
|
||||
@@ -2,6 +2,6 @@ export * from './account'
|
||||
export * from './actions'
|
||||
export * from './coin'
|
||||
export * from './contract'
|
||||
export * from './network'
|
||||
export * from './queries'
|
||||
export * from './vesting'
|
||||
export * from './network'
|
||||
export * from './queries'
|
||||
@@ -1,6 +1,6 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { majorToMinor, minorToMajor } from '.'
|
||||
import { Coin, OriginalVestingResponse } from '../types'
|
||||
import { Coin, OriginalVestingResponse, Period } from '../types'
|
||||
|
||||
export const getLockedCoins = async (address: string): Promise<Coin> => {
|
||||
const res: Coin = await invoke('locked_coins', { address })
|
||||
@@ -31,3 +31,5 @@ export const withdrawVestedCoins = async (amount: string) => {
|
||||
const minor = await majorToMinor(amount)
|
||||
await invoke('withdraw_vested_coins', { amount: { amount: minor.amount, denom: 'Minor' } })
|
||||
}
|
||||
|
||||
export const getCurrentVestingPeriod = async (address: string): Promise<Period> => await invoke('get_current_vesting_period', {address})
|
||||
|
||||
@@ -18,3 +18,4 @@ export * from './mixnodestatusresponse'
|
||||
export * from './inclusionprobabilityresponse'
|
||||
export * from './network'
|
||||
export * from './originalvestingresponse'
|
||||
export * from './period'
|
||||
@@ -1 +1 @@
|
||||
export type Period = "Before" | number | "After";
|
||||
export type Period = "Before" | {In: number} | "After";
|
||||
@@ -2,7 +2,7 @@ import { invoke } from '@tauri-apps/api'
|
||||
import bs58 from 'bs58'
|
||||
import { minor, valid } from 'semver'
|
||||
import { userBalance, majorToMinor, getGasFee } from '../requests'
|
||||
import { Coin, Network, TCurrency } from '../types'
|
||||
import { Coin, Network, Period, TCurrency } from '../types'
|
||||
|
||||
export const validateKey = (key: string, bytesLength: number): boolean => {
|
||||
// it must be a valid base58 key
|
||||
|
||||
Reference in New Issue
Block a user