From f9c73183dbfae9624e606489917bdd3a5aeb077c Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Fri, 4 Mar 2022 13:35:01 +0000 Subject: [PATCH] use new vesting requests and types --- nym-wallet/src-tauri/src/main.rs | 1 + .../src-tauri/src/operations/vesting/bond.rs | 11 ++++++ nym-wallet/src/requests/actions.ts | 17 +++------ nym-wallet/src/requests/vesting.ts | 36 ++++++++++++++++++- .../src/types/corenodestatusresponse.ts | 4 --- nym-wallet/src/types/global.ts | 10 +++++- nym-wallet/src/types/rust/index.ts | 1 + nym-wallet/src/utils/index.ts | 2 +- 8 files changed, 62 insertions(+), 20 deletions(-) delete mode 100644 nym-wallet/src/types/corenodestatusresponse.ts diff --git a/nym-wallet/src-tauri/src/main.rs b/nym-wallet/src-tauri/src/main.rs index 4de61bb5bd..796793497c 100644 --- a/nym-wallet/src-tauri/src/main.rs +++ b/nym-wallet/src-tauri/src/main.rs @@ -66,6 +66,7 @@ fn main() { vesting::bond::vesting_unbond_gateway, vesting::bond::vesting_unbond_mixnode, vesting::bond::withdraw_vested_coins, + vesting::bond::vesting_update_mixnode, vesting::delegate::vesting_delegate_to_mixnode, vesting::delegate::vesting_undelegate_from_mixnode, vesting::queries::delegated_free, diff --git a/nym-wallet/src-tauri/src/operations/vesting/bond.rs b/nym-wallet/src-tauri/src/operations/vesting/bond.rs index c90499bbbe..1739f2e98a 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/bond.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/bond.rs @@ -64,3 +64,14 @@ pub async fn withdraw_vested_coins( nymd_client!(state).withdraw_vested_coins(amount).await?; Ok(()) } + +#[tauri::command] +pub async fn vesting_update_mixnode( + profit_margin_percent: u8, + state: tauri::State<'_, Arc>>, +) -> Result<(), BackendError> { + nymd_client!(state) + .vesting_update_mixnode_config(profit_margin_percent) + .await?; + Ok(()) +} diff --git a/nym-wallet/src/requests/actions.ts b/nym-wallet/src/requests/actions.ts index 59417db32d..8a8079d4ce 100644 --- a/nym-wallet/src/requests/actions.ts +++ b/nym-wallet/src/requests/actions.ts @@ -1,17 +1,8 @@ import { invoke } from '@tauri-apps/api' -import { Coin, DelegationResult, EnumNodeType, Gateway, MixNode, TauriTxResult } from '../types' +import { Coin, DelegationResult, EnumNodeType, Gateway, MixNode, TauriTxResult, TBondArgs } from '../types' -export const bond = async ({ - type, - data, - pledge, - ownerSignature, -}: { - type: EnumNodeType - data: MixNode | Gateway - pledge: Coin - ownerSignature: string -}): Promise => await invoke(`bond_${type}`, { [type]: data, ownerSignature, pledge }) +export const bond = async ({ type, data, pledge, ownerSignature }: TBondArgs): Promise => + await invoke(`bond_${type}`, { [type]: data, ownerSignature, pledge }) export const unbond = async (type: EnumNodeType) => await invoke(`unbond_${type}`) @@ -36,5 +27,5 @@ export const undelegate = async ({ export const send = async (args: { amount: Coin; address: string; memo: string }): Promise => await invoke('send', args) -export const updateMixnode = async ({ profitMarginPercent }: { profitMarginPercent: number }) => +export const updateMixnode = async (profitMarginPercent: number) => await invoke('update_mixnode', { profitMarginPercent }) diff --git a/nym-wallet/src/requests/vesting.ts b/nym-wallet/src/requests/vesting.ts index dd2b020b6d..2917eec610 100644 --- a/nym-wallet/src/requests/vesting.ts +++ b/nym-wallet/src/requests/vesting.ts @@ -1,7 +1,16 @@ import { invoke } from '@tauri-apps/api' import { VestingAccountInfo } from 'src/types/rust/vestingaccountinfo' import { majorToMinor, minorToMajor } from '.' -import { Coin, DelegationResult, OriginalVestingResponse, Period } from '../types' +import { + Coin, + DelegationResult, + EnumNodeType, + Gateway, + MixNode, + OriginalVestingResponse, + Period, + PledgeData, +} from '../types' export const getLockedCoins = async (address: string): Promise => { const res: Coin = await invoke('locked_coins', { address }) @@ -36,6 +45,20 @@ export const withdrawVestedCoins = async (amount: string) => { export const getCurrentVestingPeriod = async (address: string): Promise => await invoke('get_current_vesting_period', { address }) +export const vestingBond = async ({ + type, + data, + pledge, + ownerSignature, +}: { + type: EnumNodeType + data: MixNode | Gateway + pledge: Coin + ownerSignature: string +}): Promise => await invoke(`vesting_bond_${type}`, { [type]: data, ownerSignature, pledge }) + +export const vestingUnbond = async (type: EnumNodeType) => await invoke(`vesting_unbond_${type}`) + export const vestingDelegateToMixnode = async ({ identity, amount, @@ -49,3 +72,14 @@ export const vestingUnelegateFromMixnode = async (identity: string): Promise => await invoke('get_account_info', { address }) + +export const getVestingPledgeInfo = async ({ + address, + type, +}: { + address?: string + type: EnumNodeType +}): Promise => await invoke(`vesting_get_${type}_pledge`, { address }) + +export const vestingUpdateMixnode = async (profitMarginPercent: number) => + await invoke('vesting_update_mixnode', { profitMarginPercent }) diff --git a/nym-wallet/src/types/corenodestatusresponse.ts b/nym-wallet/src/types/corenodestatusresponse.ts deleted file mode 100644 index 2a743b37a9..0000000000 --- a/nym-wallet/src/types/corenodestatusresponse.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface CoreNodeStatusResponse { - identity: string; - count: number; -} \ No newline at end of file diff --git a/nym-wallet/src/types/global.ts b/nym-wallet/src/types/global.ts index 7578dd99a1..fecaee0423 100644 --- a/nym-wallet/src/types/global.ts +++ b/nym-wallet/src/types/global.ts @@ -1,4 +1,4 @@ -import { Coin, Denom, MixNode } from '.' +import { Coin, Denom, Gateway, MixNode, PledgeData } from '.' export enum EnumNodeType { mixnode = 'mixnode', @@ -8,6 +8,7 @@ export enum EnumNodeType { export type TNodeOwnership = { hasOwnership: boolean nodeType?: EnumNodeType + vestingPledge?: PledgeData } export type TClientDetails = { @@ -54,6 +55,13 @@ export type TMixnodeBondDetails = { proxy: any } +export type TBondArgs = { + type: EnumNodeType + data: MixNode | Gateway + pledge: Coin + ownerSignature: string +} + export type TCurrency = { minor: 'UNYM' | 'UNYMT' major: 'NYM' | 'NYMT' diff --git a/nym-wallet/src/types/rust/index.ts b/nym-wallet/src/types/rust/index.ts index 5b20cf6e1f..64c745d75c 100644 --- a/nym-wallet/src/types/rust/index.ts +++ b/nym-wallet/src/types/rust/index.ts @@ -20,3 +20,4 @@ export * from './network' export * from './originalvestingresponse' export * from './vestingperiod' export * from './vestingaccountinfo' +export * from './pledgedata' diff --git a/nym-wallet/src/utils/index.ts b/nym-wallet/src/utils/index.ts index bf1de2efd0..8662ac9f88 100644 --- a/nym-wallet/src/utils/index.ts +++ b/nym-wallet/src/utils/index.ts @@ -2,7 +2,7 @@ import { invoke } from '@tauri-apps/api' import { appWindow } from '@tauri-apps/api/window' import bs58 from 'bs58' import { minor, valid } from 'semver' -import { userBalance, majorToMinor, getGasFee } from '../requests' +import { userBalance, majorToMinor } from '../requests' import { Coin, Network, Period, TCurrency } from '../types' export const validateKey = (key: string, bytesLength: number): boolean => {