fix issues with profit margin throwing non required errors
- all is working
This commit is contained in:
@@ -116,7 +116,7 @@ export const UpdateCostParametersModal = ({
|
||||
<Alert severity="warning">
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
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.
|
||||
</Typography>
|
||||
</Alert>
|
||||
</Box>
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -28,6 +28,16 @@ export const NodeSettings = () => {
|
||||
|
||||
const [confirmationDetails, setConfirmationDetails] = useState<ConfirmationDetailProps | undefined>();
|
||||
const [value, setValue] = React.useState<NavItems>('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 = () => {
|
||||
<NodeCostParametersPage
|
||||
bondedNode={bondedNode}
|
||||
onConfirm={handleUpdateCostParameters}
|
||||
onError={handleError}
|
||||
onError={handleError}
|
||||
onUpdateData={handleCostParametersUpdate}
|
||||
/>
|
||||
)}
|
||||
{value === 'Unbond' && bondedNode && (
|
||||
|
||||
Reference in New Issue
Block a user