bugfix: wallet backend fixes (#5070)
* fixed simulation arguments * make sure 'try_convert_pubkey_to_node_id' checks for native nymnodes
This commit is contained in:
committed by
GitHub
parent
b9d1fc40e7
commit
9f8bf2d080
@@ -115,7 +115,7 @@ fn main() {
|
||||
utils::owns_mixnode,
|
||||
utils::owns_nym_node,
|
||||
utils::get_env,
|
||||
utils::try_convert_pubkey_to_mix_id,
|
||||
utils::try_convert_pubkey_to_node_id,
|
||||
utils::default_mixnode_cost_params,
|
||||
nym_api::status::compute_mixnode_reward_estimation,
|
||||
nym_api::status::gateway_core_node_status,
|
||||
@@ -178,8 +178,8 @@ fn main() {
|
||||
simulate::mixnet::simulate_update_mixnode_config,
|
||||
simulate::mixnet::simulate_update_mixnode_cost_params,
|
||||
simulate::mixnet::simulate_update_gateway_config,
|
||||
simulate::mixnet::simulate_delegate_to_mixnode,
|
||||
simulate::mixnet::simulate_undelegate_from_mixnode,
|
||||
simulate::mixnet::simulate_delegate_to_node,
|
||||
simulate::mixnet::simulate_undelegate_from_node,
|
||||
simulate::vesting::simulate_vesting_delegate_to_mixnode,
|
||||
simulate::vesting::simulate_vesting_undelegate_from_mixnode,
|
||||
simulate::vesting::simulate_vesting_bond_gateway,
|
||||
|
||||
@@ -184,7 +184,7 @@ pub async fn simulate_update_gateway_config(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn simulate_delegate_to_mixnode(
|
||||
pub async fn simulate_delegate_to_node(
|
||||
node_id: NodeId,
|
||||
amount: DecCoin,
|
||||
state: tauri::State<'_, WalletState>,
|
||||
@@ -193,7 +193,7 @@ pub async fn simulate_delegate_to_mixnode(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn simulate_undelegate_from_mixnode(
|
||||
pub async fn simulate_undelegate_from_node(
|
||||
node_id: NodeId,
|
||||
state: tauri::State<'_, WalletState>,
|
||||
) -> Result<FeeDetails, BackendError> {
|
||||
|
||||
@@ -55,16 +55,34 @@ pub async fn owns_nym_node(state: tauri::State<'_, WalletState>) -> Result<bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn try_convert_pubkey_to_mix_id(
|
||||
pub async fn try_convert_pubkey_to_node_id(
|
||||
state: tauri::State<'_, WalletState>,
|
||||
mix_identity: IdentityKey,
|
||||
) -> Result<Option<NodeId>, BackendError> {
|
||||
let res = nyxd_client!(state)
|
||||
.get_mixnode_details_by_identity(mix_identity)
|
||||
.await?;
|
||||
Ok(res
|
||||
let guard = state.read().await;
|
||||
let client = guard.current_client()?;
|
||||
|
||||
// first try native nym-node
|
||||
if let Some(node) = client
|
||||
.nyxd
|
||||
.get_nymnode_details_by_identity(mix_identity.clone())
|
||||
.await?
|
||||
.details
|
||||
{
|
||||
return Ok(Some(node.node_id()));
|
||||
}
|
||||
|
||||
// fallback to legacy mixnode
|
||||
if let Some(node) = client
|
||||
.nyxd
|
||||
.get_mixnode_details_by_identity(mix_identity.clone())
|
||||
.await?
|
||||
.mixnode_details
|
||||
.map(|mixnode_details| mixnode_details.mix_id()))
|
||||
{
|
||||
return Ok(Some(node.mix_id()));
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CurrencyFormField } from '@nymproject/react/currency/CurrencyFormField'
|
||||
import { CurrencyDenom, FeeDetails, DecCoin, decimalToFloatApproximation } from '@nymproject/types';
|
||||
import { Console } from 'src/utils/console';
|
||||
import { useGetFee } from 'src/hooks/useGetFee';
|
||||
import { simulateDelegateToMixnode, simulateVestingDelegateToMixnode, tryConvertIdentityToMixId } from 'src/requests';
|
||||
import { simulateDelegateToNode, simulateVestingDelegateToMixnode, tryConvertIdentityToNodeId } from 'src/requests';
|
||||
import { debounce } from 'lodash';
|
||||
import { AppContext } from 'src/context';
|
||||
import { SimpleModal } from '../Modals/SimpleModal';
|
||||
@@ -152,7 +152,7 @@ export const DelegateModal: FCWithChildren<{
|
||||
}
|
||||
|
||||
if (tokenPool === 'balance') {
|
||||
getFee(simulateDelegateToMixnode, { mixId: id, amount: value });
|
||||
getFee(simulateDelegateToNode, { nodeId: id, amount: value });
|
||||
}
|
||||
|
||||
if (tokenPool === 'locked') {
|
||||
@@ -187,16 +187,16 @@ export const DelegateModal: FCWithChildren<{
|
||||
}
|
||||
let res;
|
||||
try {
|
||||
res = await tryConvertIdentityToMixId(idKey);
|
||||
res = await tryConvertIdentityToNodeId(idKey);
|
||||
} catch (e) {
|
||||
Console.warn(`failed to resolve mix_id for "${idKey}": ${e}`);
|
||||
Console.warn(`failed to resolve node_id for "${idKey}": ${e}`);
|
||||
return;
|
||||
}
|
||||
if (res) {
|
||||
setMixId(res);
|
||||
setMixIdError(undefined);
|
||||
} else {
|
||||
setMixIdError('Mixnode with this identity does not seem to be currently bonded');
|
||||
setMixIdError('Node with this identity does not seem to be currently bonded');
|
||||
}
|
||||
}, 500),
|
||||
[],
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useContext, useEffect } from 'react';
|
||||
import { Box, SxProps } from '@mui/material';
|
||||
import { FeeDetails } from '@nymproject/types';
|
||||
import { useGetFee } from 'src/hooks/useGetFee';
|
||||
import { simulateUndelegateFromMixnode, simulateVestingUndelegateFromMixnode } from 'src/requests';
|
||||
import { simulateUndelegateFromNode, simulateVestingUndelegateFromMixnode } from 'src/requests';
|
||||
import { AppContext } from 'src/context';
|
||||
import { ModalFee } from '../Modals/ModalFee';
|
||||
import { ModalListItem } from '../Modals/ModalListItem';
|
||||
@@ -27,7 +27,7 @@ export const UndelegateModal: FCWithChildren<{
|
||||
useEffect(() => {
|
||||
if (usesVestingContractTokens) getFee(simulateVestingUndelegateFromMixnode, { mixId });
|
||||
else {
|
||||
getFee(simulateUndelegateFromMixnode, mixId);
|
||||
getFee(simulateUndelegateFromNode, mixId);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ export const simulateUpdateMixnodeConfig = async (update: MixNodeConfigUpdate) =
|
||||
export const simulateUpdateGatewayConfig = async (update: GatewayConfigUpdate) =>
|
||||
invokeWrapper<FeeDetails>('simulate_update_gateway_config', { update });
|
||||
|
||||
export const simulateDelegateToMixnode = async (args: { mixId: number; amount: DecCoin }) =>
|
||||
invokeWrapper<FeeDetails>('simulate_delegate_to_mixnode', args);
|
||||
export const simulateDelegateToNode = async (args: { nodeId: number; amount: DecCoin }) =>
|
||||
invokeWrapper<FeeDetails>('simulate_delegate_to_node', args);
|
||||
|
||||
export const simulateUndelegateFromMixnode = async (mixId: number) =>
|
||||
invokeWrapper<FeeDetails>('simulate_undelegate_from_mixnode', { mixId });
|
||||
export const simulateUndelegateFromNode = async (nodeId: number) =>
|
||||
invokeWrapper<FeeDetails>('simulate_undelegate_from_node', { nodeId });
|
||||
|
||||
export const simulateClaimDelegatorReward = async (mixId: number) =>
|
||||
invokeWrapper<FeeDetails>('simulate_claim_delegator_reward', { mixId });
|
||||
export const simulateClaimDelegatorReward = async (nodeId: number) =>
|
||||
invokeWrapper<FeeDetails>('simulate_claim_delegator_reward', { nodeId });
|
||||
|
||||
export const simulateVestingClaimDelegatorReward = async (mixId: number) =>
|
||||
invokeWrapper<FeeDetails>('simulate_vesting_claim_delegator_reward', { mixId });
|
||||
|
||||
@@ -4,8 +4,8 @@ import { invokeWrapper } from './wrapper';
|
||||
|
||||
export const getEnv = async () => invokeWrapper<AppEnv>('get_env');
|
||||
|
||||
export const tryConvertIdentityToMixId = async (mixIdentity: string) =>
|
||||
invokeWrapper<number | null>('try_convert_pubkey_to_mix_id', { mixIdentity });
|
||||
export const tryConvertIdentityToNodeId = async (mixIdentity: string) =>
|
||||
invokeWrapper<number | null>('try_convert_pubkey_to_node_id', { mixIdentity });
|
||||
|
||||
export const getDefaultNodeCostParams = async (profitMarginPercent: string) =>
|
||||
invokeWrapper<NodeCostParams>('default_mixnode_cost_params', { profitMarginPercent });
|
||||
|
||||
Reference in New Issue
Block a user