diff --git a/nym-wallet/src/components/Bonding/modals/NodeCostParametersModals.tsx b/nym-wallet/src/components/Bonding/modals/NodeCostParametersModals.tsx index 80c052ea3d..96b021e9d6 100644 --- a/nym-wallet/src/components/Bonding/modals/NodeCostParametersModals.tsx +++ b/nym-wallet/src/components/Bonding/modals/NodeCostParametersModals.tsx @@ -116,7 +116,7 @@ export const UpdateCostParametersModal = ({ This action will overwrite your existing profit margin and operating cost settings. - Only one cost parameter update is allowed per epoch. + Only one cost parameter update is allowed per interval. diff --git a/nym-wallet/src/context/bonding.tsx b/nym-wallet/src/context/bonding.tsx index 364d1f7d75..6a8a40b37b 100644 --- a/nym-wallet/src/context/bonding.tsx +++ b/nym-wallet/src/context/bonding.tsx @@ -268,15 +268,13 @@ export const BondingContextProvider: FCWithChildren = ({ children }): JSX.Elemen let tx; setIsLoading(true); try { - console.log('BondingContext.updateCostParameters called with:', { - profitMarginPercent, - intervalOperatingCost, - fee - }); - - // Convert from percentage (20-50) to decimal (0.2-0.5) + // Validate input before proceeding + if (!profitMarginPercent || parseFloat(profitMarginPercent) < 20 || parseFloat(profitMarginPercent) > 50) { + throw new Error('Profit margin must be between 20% and 50%'); + } + + // Convert from percentage to decimal const decimalProfitMargin = (parseFloat(profitMarginPercent) / 100).toString(); - console.log('Converted profit margin to decimal:', decimalProfitMargin); const operatingCost = intervalOperatingCost || '0'; @@ -287,29 +285,20 @@ export const BondingContextProvider: FCWithChildren = ({ children }): JSX.Elemen amount: operatingCost } }; - console.log('Created NodeCostParams:', costParams); - - if (parseFloat(decimalProfitMargin) < 0.2 || parseFloat(decimalProfitMargin) > 0.5) { - throw new Error('Profit margin must be between 20% and 50%'); - } - - console.log('Calling updateNymNodeParams with:', costParams, fee?.fee); + tx = await updateNymNodeParams(costParams, fee?.fee); - console.log('Result from updateNymNodeParams:', tx); - + if (clientDetails?.client_address) { await getNodeDetails(clientDetails?.client_address); } return tx; } catch (e) { - Console.warn('Error in updateCostParameters:', e); - console.error('Error in updateCostParameters:', e); setError(`an error occurred: ${e}`); + throw e; } finally { setIsLoading(false); } - return undefined; }; const memoizedValue = useMemo( diff --git a/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx b/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx index 5f9644d367..d133f71b04 100644 --- a/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx +++ b/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx @@ -28,6 +28,16 @@ export const NodeSettings = () => { const [confirmationDetails, setConfirmationDetails] = useState(); const [value, setValue] = React.useState('General'); + + // Add state to store cost parameters values + const [costParametersData, setCostParametersData] = useState<{ + profitMarginPercent: string; + intervalOperatingCost: string; + fee?: FeeDetails; + }>({ + profitMarginPercent: '', + intervalOperatingCost: '', + }); const handleChange = (_: React.SyntheticEvent, tab: string) => { setValue(tab as NavItems); @@ -53,16 +63,38 @@ export const NodeSettings = () => { }); }; - const handleUpdateCostParameters = async () => { - const tx = await updateCostParameters('0', '0', undefined); - setConfirmationDetails({ - status: 'success', - title: 'Cost Parameters Updated', - subtitle: 'Your cost parameters have been successfully updated', - txUrl: tx?.transaction_hash ? `${urls(network).blockExplorer}/transaction/${tx.transaction_hash}` : undefined, + // Function to update state from NodeCostParametersPage + const handleCostParametersUpdate = ( + profitMarginPercent: string, + intervalOperatingCost: string, + fee?: FeeDetails + ) => { + setCostParametersData({ + profitMarginPercent, + intervalOperatingCost, + fee, }); }; + const handleUpdateCostParameters = async () => { + try { + const { profitMarginPercent, intervalOperatingCost, fee } = costParametersData; + + const uNymAmount = String(Math.floor(Number(intervalOperatingCost || '0') * 1000000)); + + const tx = await updateCostParameters(profitMarginPercent, uNymAmount, fee); + + setConfirmationDetails({ + status: 'success', + title: 'Cost Parameters Updated', + subtitle: 'Your cost parameters have been successfully updated', + txUrl: tx?.transaction_hash ? `${urls(network).blockExplorer}/transaction/${tx.transaction_hash}` : undefined, + }); + } catch (error) { + handleError(String(error)); + } + }; + const handleError = (error: string) => { setConfirmationDetails({ status: 'error', @@ -140,7 +172,8 @@ export const NodeSettings = () => { )} {value === 'Unbond' && bondedNode && (