Skip to content

Commit

Permalink
update crosschain fee
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonHJ committed Aug 9, 2023
1 parent 6a927f8 commit cbd6b8e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 60 deletions.
Expand Up @@ -16,8 +16,8 @@ const inputCom = <Input disabled={true} />
@observer
class CrossETHConfirmForm extends Component {
render() {
const { form: { getFieldDecorator }, from, loading, sendTrans, userNetWorkFee, handleCancel, tokenSymbol, transParams, tokenPairs, type, crosschainFee, received } = this.props;
const { amount, toAddr, storeman } = this.props.transParams[from];
const { form: { getFieldDecorator }, from, loading, sendTrans, userNetWorkFee, handleCancel, tokenSymbol, transParams, tokenPairs, type, received } = this.props;
const { amount, toAddr, storeman, crosschainFee } = this.props.transParams[from];
const chainPairId = transParams[from].chainPairId;
const info = Object.assign({}, tokenPairs[chainPairId]);
let fromChain = type === INBOUND ? info.fromChainName : info.toChainName;
Expand Down
Expand Up @@ -16,8 +16,8 @@ const inputCom = <Input disabled={true} />
@observer
class CrossWANConfirmForm extends Component {
render() {
const { form: { getFieldDecorator }, from, loading, sendTrans, estimateFee, handleCancel, tokenSymbol, transParams, tokenPairs, type, userNetWorkFee, crosschainFee, received, amount } = this.props;
const { toAddr, storeman } = this.props.transParams[from];
const { form: { getFieldDecorator }, from, loading, sendTrans, estimateFee, handleCancel, tokenSymbol, transParams, tokenPairs, type, userNetWorkFee, received, amount } = this.props;
const { toAddr, storeman, crosschainFee } = this.props.transParams[from];
const chainPairId = transParams[from].chainPairId;
const info = Object.assign({}, tokenPairs[chainPairId]);
let fromChain = type === INBOUND ? info.fromChainName : info.toChainName;
Expand Down
Expand Up @@ -17,8 +17,8 @@ const inputCom = <Input disabled={true} />
@observer
class ConfirmForm extends Component {
render() {
const { visible, form: { getFieldDecorator }, from, loading, sendTrans, estimateFee, handleCancel, tokenSymbol, transParams, tokenPairs, currTokenPairId, type, userNetWorkFee, crosschainFee, received } = this.props;
const { amount, toAddr, storeman, crossType } = transParams[from];
const { visible, form: { getFieldDecorator }, from, loading, sendTrans, estimateFee, handleCancel, tokenSymbol, transParams, tokenPairs, currTokenPairId, type, userNetWorkFee, received } = this.props;
const { amount, toAddr, storeman, crossType, crosschainFee } = transParams[from];
const info = Object.assign({}, tokenPairs[currTokenPairId]);
let fromChain = type === INBOUND ? info.fromChainName : info.toChainName;
let desChain = type === INBOUND ? info.toChainName : info.fromChainName;
Expand Down
39 changes: 23 additions & 16 deletions src/app/components/CrossChain/CrossChainTransForm/CrossETHForm.js
Expand Up @@ -73,7 +73,8 @@ class CrossETHForm extends Component {
showAddContacts: false,
showChooseContacts: false,
networkFeeRaw: {},
operationFeeRaw: {}
operationFeeRaw: {},
totalFee: '0'
}
}

Expand Down Expand Up @@ -121,7 +122,7 @@ class CrossETHForm extends Component {
}

estimateNetworkFee = (address = '') => {
const { type, currTokenPairId, currentTokenPairInfo: info } = this.props;
const { type, currTokenPairId, currentTokenPairInfo: info, form } = this.props;
const { ancestorDecimals } = info;

estimateCrossChainNetworkFee(type === INBOUND ? 'ETH' : 'WAN', type === INBOUND ? 'WAN' : 'ETH', { tokenPairID: currTokenPairId, address }).then(res => {
Expand All @@ -134,15 +135,15 @@ class CrossETHForm extends Component {
minNetworkFeeLimit: res.isPercent ? new BigNumber(res.minFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
maxNetworkFeeLimit: res.isPercent ? new BigNumber(res.maxFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
});
this.updateCrosschainFee();
this.updateCrosschainFee(form.getFieldValue('amount'));
}).catch(err => {
console.log('err:', err);
message.warn(intl.get('CrossChainTransForm.getNetworkFeeFailed'));
});
}

estimateOperationFee = (address = '') => {
const { type, currTokenPairId, currentTokenPairInfo: info } = this.props;
const { type, currTokenPairId, currentTokenPairInfo: info, form } = this.props;
const { ancestorDecimals } = info;

estimateCrossChainOperationFee(type === INBOUND ? 'ETH' : 'WAN', type === INBOUND ? 'WAN' : 'ETH', { tokenPairID: currTokenPairId, address }).then(res => {
Expand All @@ -155,7 +156,7 @@ class CrossETHForm extends Component {
minOperationFeeLimit: res.isPercent ? new BigNumber(res.minFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
maxOperationFeeLimit: res.isPercent ? new BigNumber(res.maxFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
});
this.updateCrosschainFee();
this.updateCrosschainFee(form.getFieldValue('amount'));
}).catch(err => {
console.log('err:', err);
message.warn(intl.get('CrossChainTransForm.getOperationFeeFailed'));
Expand Down Expand Up @@ -246,10 +247,11 @@ class CrossETHForm extends Component {

updateCrosschainFee = (value = '0') => {
const { isPercentNetworkFee, isPercentOperationFee, networkFeeRaw, operationFeeRaw, percentNetworkFee, percentOperationFee, minNetworkFeeLimit, maxNetworkFeeLimit, minOperationFeeLimit, maxOperationFeeLimit, discountPercentOperationFee, discountPercentNetworkFee } = this.state;
const { type } = this.props;
if (!value) {
value = this.props.form.getFieldValue('amount')
}
let finnalNetworkFee, finnalOperationFee;
let finnalNetworkFee, finnalOperationFee, totalFee;
if (isPercentNetworkFee) {
const tmp = new BigNumber(value).multipliedBy(percentNetworkFee);
const tmp1 = tmp.lt(minNetworkFeeLimit)
Expand All @@ -269,8 +271,13 @@ class CrossETHForm extends Component {
} else {
finnalOperationFee = new BigNumber(operationFeeRaw).multipliedBy(discountPercentOperationFee).toString(10);
}
if (type === INBOUND) {
totalFee = `${new BigNumber(finnalNetworkFee).plus(finnalOperationFee).toString()} ETH`;
} else {
totalFee = `${new BigNumber(finnalNetworkFee).toString()} WAN + ${new BigNumber(finnalOperationFee).toString()} ETH`;
}

this.setState({ networkFee: finnalNetworkFee, operationFee: finnalOperationFee });
this.setState({ networkFee: finnalNetworkFee, operationFee: finnalOperationFee, totalFee });

return [finnalNetworkFee, finnalOperationFee];
}
Expand Down Expand Up @@ -508,10 +515,10 @@ class CrossETHForm extends Component {
}

render() {
const { loading, form, from, settings, smgList, gasPrice, chainType, balance, type, account, getChainAddressInfoByChain, currentTokenPairInfo: info, coinPriceObj } = this.props;
const { advancedVisible, advanced, advancedFee, operationFee, networkFee, showChooseContacts, isNewContacts, showAddContacts, contactsList, receivedAmount } = this.state;
const { loading, form, from, settings, smgList, gasPrice, chainType, balance, type, account, getChainAddressInfoByChain, currentTokenPairInfo: info } = this.props;
const { advancedVisible, advanced, advancedFee, operationFee, networkFee, showChooseContacts, isNewContacts, showAddContacts, contactsList, receivedAmount, totalFee } = this.state;
const { getFieldDecorator } = form;
let gasFee, gasFeeWithUnit, totalFee, desChain, selectedList, title, toAccountList, unit, canAdvance, feeUnit, networkFeeUnit, operationFeeUnit;
let gasFee, gasFeeWithUnit, desChain, selectedList, title, toAccountList, unit, canAdvance, feeUnit, networkFeeUnit, operationFeeUnit;
if (type === INBOUND) {
desChain = info.toChainSymbol;
toAccountList = getChainAddressInfoByChain(info.toChainSymbol);
Expand Down Expand Up @@ -551,11 +558,11 @@ class CrossETHForm extends Component {
// } else {
// totalFee = `${new BigNumber(gasFee).plus(networkFee).toString()} ${feeUnit}`;
// }
if (networkFeeUnit === operationFeeUnit) {
totalFee = `${new BigNumber(networkFee).plus(operationFee).toString()} ${networkFeeUnit}`;
} else {
totalFee = `${new BigNumber(networkFee).toString()} ${networkFeeUnit} + ${new BigNumber(operationFee).toString()} ${operationFeeUnit}`;
}
// if (networkFeeUnit === operationFeeUnit) {
// totalFee = `${new BigNumber(networkFee).plus(operationFee).toString()} ${networkFeeUnit}`;
// } else {
// totalFee = `${new BigNumber(networkFee).toString()} ${networkFeeUnit} + ${new BigNumber(operationFee).toString()} ${operationFeeUnit}`;
// }

gasFeeWithUnit = `${removeRedundantDecimal(gasFee)} ${feeUnit}`;

Expand Down Expand Up @@ -720,7 +727,7 @@ class CrossETHForm extends Component {
</div>
</Spin>
</Modal>
{ this.state.confirmVisible && <Confirm received={form.getFieldValue('receive')} tokenSymbol={unit} chainType={chainType} userNetWorkFee={gasFeeWithUnit} crosschainFee={form.getFieldValue('totalFee')} handleCancel={this.handleConfirmCancel} sendTrans={this.sendTrans} from={from} loading={loading} type={type} />}
{ this.state.confirmVisible && <Confirm received={form.getFieldValue('receive')} tokenSymbol={unit} chainType={chainType} userNetWorkFee={gasFeeWithUnit} handleCancel={this.handleConfirmCancel} sendTrans={this.sendTrans} from={from} loading={loading} type={type} />}
{advancedVisible && <AdvancedCrossChainModal chainType={chainType} onCancel={this.handleAdvancedCancel} onSave={this.handleSaveOption} from={from} />}
{
showAddContacts && <AddContactsModalForm handleSave={this.handleCreate} onCancel={this.handleShowAddContactModal} address={form.getFieldValue('to')} chain={getFullChainName(desChain)}></AddContactsModalForm>
Expand Down
38 changes: 23 additions & 15 deletions src/app/components/CrossChain/CrossChainTransForm/CrossWANForm.js
Expand Up @@ -71,7 +71,8 @@ class CrossWANForm extends Component {
discountPercentNetworkFee: '1',
discountPercentOperationFee: '1',
networkFeeRaw: {},
operationFeeRaw: {}
operationFeeRaw: {},
totalFee: '0'
}
}

Expand Down Expand Up @@ -118,7 +119,7 @@ class CrossWANForm extends Component {
}

estimateNetworkFee = (address = '') => {
const { type, currTokenPairId, currentTokenPairInfo: info } = this.props;
const { type, currTokenPairId, currentTokenPairInfo: info, form } = this.props;
const { ancestorDecimals } = info;

estimateCrossChainNetworkFee(type === INBOUND ? 'WAN' : 'ETH', type === INBOUND ? 'ETH' : 'WAN', { tokenPairID: currTokenPairId, address }).then(res => {
Expand All @@ -131,15 +132,15 @@ class CrossWANForm extends Component {
minNetworkFeeLimit: res.isPercent ? new BigNumber(res.minFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
maxNetworkFeeLimit: res.isPercent ? new BigNumber(res.maxFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0
});
this.updateCrosschainFee();
this.updateCrosschainFee(form.getFieldValue('amount'));
}).catch(err => {
console.log('err:', err);
message.warn(intl.get('CrossChainTransForm.getNetworkFeeFailed'));
});
}

estimateOperationFee = (address = '') => {
const { type, currTokenPairId, currentTokenPairInfo: info } = this.props;
const { type, currTokenPairId, currentTokenPairInfo: info, form } = this.props;
const { ancestorDecimals } = info;

estimateCrossChainOperationFee(type === INBOUND ? 'WAN' : 'ETH', type === INBOUND ? 'ETH' : 'WAN', { tokenPairID: currTokenPairId, address }).then(res => {
Expand All @@ -152,7 +153,7 @@ class CrossWANForm extends Component {
minOperationFeeLimit: res.isPercent ? new BigNumber(res.minFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0,
maxOperationFeeLimit: res.isPercent ? new BigNumber(res.maxFeeLimit).dividedBy(Math.pow(10, ancestorDecimals)).toString() : 0
});
this.updateCrosschainFee();
this.updateCrosschainFee(form.getFieldValue('amount'));
}).catch(err => {
console.log('err:', err);
message.warn(intl.get('CrossChainTransForm.getOperationFeeFailed'));
Expand Down Expand Up @@ -260,10 +261,11 @@ class CrossWANForm extends Component {

updateCrosschainFee = (value = '0') => {
const { isPercentNetworkFee, isPercentOperationFee, networkFeeRaw, operationFeeRaw, percentNetworkFee, percentOperationFee, minNetworkFeeLimit, maxNetworkFeeLimit, minOperationFeeLimit, maxOperationFeeLimit, discountPercentNetworkFee, discountPercentOperationFee } = this.state;
const { type } = this.props;
if (!value) {
value = this.props.form.getFieldValue('amount')
}
let finnalNetworkFee, finnalOperationFee;
let finnalNetworkFee, finnalOperationFee, totalFee;
if (isPercentNetworkFee) {
const tmp = new BigNumber(value).multipliedBy(percentNetworkFee);
const tmp1 = tmp.lt(minNetworkFeeLimit)
Expand All @@ -283,7 +285,13 @@ class CrossWANForm extends Component {
finnalOperationFee = new BigNumber(operationFeeRaw).multipliedBy(discountPercentOperationFee).toString(10);
}

this.setState({ networkFee: finnalNetworkFee, operationFee: finnalOperationFee });
if (type === INBOUND) {
totalFee = `${new BigNumber(finnalNetworkFee).plus(finnalOperationFee).toString()} WAN`;
} else {
totalFee = `${new BigNumber(finnalNetworkFee).toString()} ETH + ${new BigNumber(finnalOperationFee).toString()} WAN`;
}

this.setState({ networkFee: finnalNetworkFee, operationFee: finnalOperationFee, totalFee });

return [finnalNetworkFee, finnalOperationFee];
}
Expand Down Expand Up @@ -524,9 +532,9 @@ class CrossWANForm extends Component {

render() {
const { loading, form, from, settings, smgList, chainType, symbol, gasPrice, type, estimateFee, balance, getChainAddressInfoByChain, record, currentTokenPairInfo: info, coinPriceObj, contacts } = this.props;
const { advancedVisible, advanced, advancedFee, operationFee, networkFee, showChooseContacts, isNewContacts, showAddContacts, contactsList, receivedAmount } = this.state;
const { advancedVisible, advanced, advancedFee, operationFee, networkFee, showChooseContacts, isNewContacts, showAddContacts, contactsList, receivedAmount, totalFee } = this.state;
const { getFieldDecorator } = form;
let gasFee, gasFeeWithUnit, totalFee, desChain, selectedList, title, fromAccount, toAccountList, unit, canAdvance, feeUnit, networkFeeUnit, operationFeeUnit;
let gasFee, gasFeeWithUnit, desChain, selectedList, title, fromAccount, toAccountList, unit, canAdvance, feeUnit, networkFeeUnit, operationFeeUnit;
if (type === INBOUND) {
desChain = info.toChainSymbol;
toAccountList = getChainAddressInfoByChain(info.toChainSymbol);
Expand Down Expand Up @@ -563,11 +571,11 @@ class CrossWANForm extends Component {
let defaultSelectStoreman = smgList.length === 0 ? '' : smgList[0].groupId;

// totalFee = `${new BigNumber(networkFee).toString()} ${networkFeeUnit} + ${new BigNumber(operationFee).toString()} ${operationFeeUnit}`;
if (networkFeeUnit === operationFeeUnit) {
totalFee = `${new BigNumber(networkFee).plus(operationFee).toString()} ${networkFeeUnit}`;
} else {
totalFee = `${new BigNumber(networkFee).toString()} ${networkFeeUnit} + ${new BigNumber(operationFee).toString()} ${operationFeeUnit}`;
}
// if (networkFeeUnit === operationFeeUnit) {
// totalFee = `${new BigNumber(networkFee).plus(operationFee).toString()} ${networkFeeUnit}`;
// } else {
// totalFee = `${new BigNumber(networkFee).toString()} ${networkFeeUnit} + ${new BigNumber(operationFee).toString()} ${operationFeeUnit}`;
// }
gasFeeWithUnit = `${removeRedundantDecimal(gasFee)} ${feeUnit}`;

const operationFeeWithUnit = `${removeRedundantDecimal(operationFee)} ${operationFeeUnit}`;
Expand Down Expand Up @@ -739,7 +747,7 @@ class CrossWANForm extends Component {
</div>
</Spin>
</Modal>
{this.state.confirmVisible && <Confirm tokenSymbol={unit} amount={form.getFieldValue('amount')} received={form.getFieldValue('receive')} chainType={chainType} userNetWorkFee={gasFeeWithUnit} crosschainFee={form.getFieldValue('totalFee')} handleCancel={this.handleConfirmCancel} sendTrans={this.sendTrans} from={from} loading={loading} type={type} />}
{this.state.confirmVisible && <Confirm tokenSymbol={unit} amount={form.getFieldValue('amount')} received={form.getFieldValue('receive')} chainType={chainType} userNetWorkFee={gasFeeWithUnit} handleCancel={this.handleConfirmCancel} sendTrans={this.sendTrans} from={from} loading={loading} type={type} />}
{advancedVisible && <AdvancedCrossChainModal chainType={chainType} onCancel={this.handleAdvancedCancel} onSave={this.handleSaveOption} from={from} />}
{
showAddContacts && <AddContactsModalForm handleSave={this.handleCreate} onCancel={this.handleShowAddContactModal} address={form.getFieldValue('to')} chain={getFullChainName(desChain)}></AddContactsModalForm>
Expand Down

0 comments on commit cbd6b8e

Please sign in to comment.