fix breaking changes + add vesting total period
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { Balance, Coin } from '../types'
|
||||
import { getVestingCoins, getVestedCoins, getLockedCoins, getSpendableCoins, originalVesting } from '../requests'
|
||||
import { Balance, Coin, OriginalVestingResponse } from '../types'
|
||||
import { getVestingCoins, getVestedCoins, getLockedCoins, getSpendableCoins, getOriginalVesting } from '../requests'
|
||||
|
||||
type TTokenAllocation = {
|
||||
[key in 'vesting' | 'vested' | 'locked' | 'spendable' | 'original']: Coin['amount']
|
||||
[key in 'vesting' | 'vested' | 'locked' | 'spendable' ]: Coin['amount']
|
||||
}
|
||||
|
||||
export type TUseuserBalance = {
|
||||
error?: string
|
||||
balance?: Balance
|
||||
tokenAllocation?: TTokenAllocation
|
||||
originalVesting?: OriginalVestingResponse
|
||||
isLoading: boolean
|
||||
fetchBalance: () => void
|
||||
clearBalance: () => void
|
||||
@@ -21,6 +22,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
const [balance, setBalance] = useState<Balance>()
|
||||
const [error, setError] = useState<string>()
|
||||
const [tokenAllocation, setTokenAllocation] = useState<TTokenAllocation>()
|
||||
const [originalVesting, setOriginalVesting] = useState<OriginalVestingResponse>()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const fetchBalance = useCallback(async () => {
|
||||
@@ -43,25 +45,25 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
if (address) {
|
||||
try {
|
||||
const [originalVestingValue, vestingCoins, vestedCoins, lockedCoins, spendableCoins] = await Promise.all([
|
||||
Promise.resolve({amount: "100"}),
|
||||
getOriginalVesting(address),
|
||||
getVestingCoins(address),
|
||||
getVestedCoins(address),
|
||||
getLockedCoins(address),
|
||||
getSpendableCoins(address),
|
||||
])
|
||||
|
||||
console.log(originalVestingValue, vestingCoins)
|
||||
setOriginalVesting(originalVestingValue)
|
||||
|
||||
setTokenAllocation({
|
||||
original: originalVestingValue.amount,
|
||||
vesting: vestingCoins.amount,
|
||||
vested: vestedCoins.amount,
|
||||
locked: lockedCoins.amount,
|
||||
spendable: spendableCoins.amount,
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
clearTokenAllocation()
|
||||
clearOriginalVesting()
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
setIsLoading(false)
|
||||
@@ -69,6 +71,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
|
||||
const clearBalance = () => setBalance(undefined)
|
||||
const clearTokenAllocation = () => setTokenAllocation(undefined)
|
||||
const clearOriginalVesting = () => setOriginalVesting(undefined)
|
||||
|
||||
useEffect(() => {
|
||||
handleRefresh(address)
|
||||
@@ -89,6 +92,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => {
|
||||
isLoading,
|
||||
balance,
|
||||
tokenAllocation,
|
||||
originalVesting,
|
||||
fetchBalance,
|
||||
clearBalance,
|
||||
fetchTokenAllocation,
|
||||
|
||||
@@ -123,9 +123,9 @@ const VestingTable = () => {
|
||||
const [vestedPercentage, setVestedPercentage] = useState(0)
|
||||
|
||||
const calculatPercentage = () => {
|
||||
const { tokenAllocation } = userBalance
|
||||
if (tokenAllocation?.vesting && tokenAllocation.vested && tokenAllocation.vested !== '0') {
|
||||
const percentage = Math.round((+tokenAllocation.vested / +tokenAllocation.original) * 100)
|
||||
const { tokenAllocation, originalVesting } = userBalance
|
||||
if (tokenAllocation?.vesting && tokenAllocation.vested && tokenAllocation.vested !== '0' && originalVesting) {
|
||||
const percentage = Math.round((+tokenAllocation.vested / +originalVesting?.amount.amount) * 100)
|
||||
setVestedPercentage(percentage)
|
||||
} else {
|
||||
setVestedPercentage(0)
|
||||
@@ -151,7 +151,7 @@ const VestingTable = () => {
|
||||
<TableCell sx={{ borderBottom: 'none' }}>
|
||||
{userBalance.tokenAllocation?.vesting || 'n/a'} {currency?.major}
|
||||
</TableCell>
|
||||
<TableCell sx={{ borderBottom: 'none' }}></TableCell>
|
||||
<TableCell sx={{ borderBottom: 'none' }}>{userBalance.originalVesting?.number_of_periods}</TableCell>
|
||||
<TableCell sx={{ borderBottom: 'none' }}>
|
||||
<Box display="flex" alignItems="center" gap={1}>
|
||||
<Typography
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { majorToMinor, minorToMajor } from '.'
|
||||
import { Coin } from '../types'
|
||||
import { Coin, OriginalVestingResponse } from '../types'
|
||||
|
||||
export const getLockedCoins = async (address: string): Promise<Coin> => {
|
||||
const res: Coin = await invoke('locked_coins', { address })
|
||||
@@ -21,9 +21,10 @@ export const getVestedCoins = async (vestingAccountAddress: string): Promise<Coi
|
||||
return await minorToMajor(res.amount)
|
||||
}
|
||||
|
||||
export const originalVesting = async (vestingAccountAddress: string): Promise<Coin> => {
|
||||
const res: Coin = await invoke('original_vesting', { vestingAccountAddress })
|
||||
return await minorToMajor(res.amount)
|
||||
export const getOriginalVesting = async (vestingAccountAddress: string): Promise<OriginalVestingResponse> => {
|
||||
const res: OriginalVestingResponse = await invoke('original_vesting', { vestingAccountAddress })
|
||||
const majorValue = await minorToMajor(res.amount.amount)
|
||||
return {...res, amount: majorValue}
|
||||
}
|
||||
|
||||
export const withdrawVestedCoins = async (amount: string) => {
|
||||
|
||||
@@ -17,3 +17,4 @@ export * from './mixnodestatus'
|
||||
export * from './mixnodestatusresponse'
|
||||
export * from './inclusionprobabilityresponse'
|
||||
export * from './network'
|
||||
export * from './originalvestingresponse'
|
||||
|
||||
Reference in New Issue
Block a user