1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

added slippage to trade approval (#1252)

This commit is contained in:
Norbi 2022-03-25 14:51:56 +02:00 committed by GitHub
parent 300b5b9ef3
commit 63f0b41006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -6,11 +6,13 @@ import ExplorerLink from '@shared/ExplorerLink'
import SuccessConfetti from '@shared/SuccessConfetti' import SuccessConfetti from '@shared/SuccessConfetti'
import { useWeb3 } from '@context/Web3' import { useWeb3 } from '@context/Web3'
import TokenApproval from '@shared/TokenApproval' import TokenApproval from '@shared/TokenApproval'
import Decimal from 'decimal.js'
export default function Actions({ export default function Actions({
isLoading, isLoading,
loaderMessage, loaderMessage,
successMessage, successMessage,
slippage,
txId, txId,
actionName, actionName,
amount, amount,
@ -23,6 +25,7 @@ export default function Actions({
isLoading: boolean isLoading: boolean
loaderMessage: string loaderMessage: string
successMessage: string successMessage: string
slippage?: string
txId: string txId: string
actionName: string actionName: string
amount?: string amount?: string
@ -45,6 +48,18 @@ export default function Actions({
</Button> </Button>
) )
const applySlippage = (amount: string) => {
if (!amount) return '0'
const newAmount = new Decimal(amount)
.mul(
new Decimal(1)
.plus(new Decimal(slippage).div(new Decimal(100)))
.toString()
)
.toString()
return newAmount
}
return ( return (
<> <>
<div className={styles.actions}> <div className={styles.actions}>
@ -53,7 +68,7 @@ export default function Actions({
) : actionName === 'Supply' || actionName === 'Swap' ? ( ) : actionName === 'Supply' || actionName === 'Swap' ? (
<TokenApproval <TokenApproval
actionButton={actionButton} actionButton={actionButton}
amount={amount} amount={slippage ? applySlippage(amount) : amount}
tokenAddress={tokenAddress} tokenAddress={tokenAddress}
tokenSymbol={tokenSymbol} tokenSymbol={tokenSymbol}
disabled={isDisabled} disabled={isDisabled}

View File

@ -193,6 +193,7 @@ export default function FormTrade({
loaderMessage="Swapping tokens..." loaderMessage="Swapping tokens..."
successMessage="Successfully swapped tokens." successMessage="Successfully swapped tokens."
actionName={content.trade.action} actionName={content.trade.action}
slippage={values.slippage}
amount={ amount={
values.type === 'sell' values.type === 'sell'
? values.datatoken ? values.datatoken