Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 17ac9d3

Browse files
authored
fix: deep link by swapping sooner after user interaction (#534)
* build: conedison@1.5 * fix: use conedison/sendTransaction when able * build: upgrade conedison again * test: conedison import * fix: nits
1 parent 7220284 commit 17ac9d3

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ module.exports = {
66

77
// Jest does not always resolve src/test (probably because of babel's TypeScript transpilation):
88
'^test/*': '<rootDir>/src/test',
9+
910
'@uniswap/conedison/format': '@uniswap/conedison/dist/format.js',
10-
'@uniswap/conedison/provider': '@uniswap/conedison/dist/provider.js',
11+
'@uniswap/conedison/provider': '@uniswap/conedison/dist/provider/index.js',
1112
},
1213
setupFiles: ['<rootDir>/test/setup.ts'],
1314
setupFilesAfterEnv: ['<rootDir>/test/setup-jest.ts'],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@fontsource/inter": "^4.5.1",
6363
"@popperjs/core": "^2.4.4",
6464
"@reduxjs/toolkit": "^1.6.1",
65-
"@uniswap/conedison": "^1.3.0",
65+
"@uniswap/conedison": "^1.5.1",
6666
"@uniswap/permit2-sdk": "^1.2.0",
6767
"@uniswap/redux-multicall": "^1.1.8",
6868
"@uniswap/router-sdk": "^1.3.0",

src/constants/misc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ export const BETTER_TRADE_LESS_HOPS_THRESHOLD = new Percent(JSBI.BigInt(50), BIP
4040
export const ZERO_PERCENT = new Percent('0')
4141
export const TWO_PERCENT = new Percent(JSBI.BigInt(200), BIPS_BASE)
4242
export const ONE_HUNDRED_PERCENT = new Percent('1')
43+
44+
// gas margin to ensure successful transactions
45+
export const TX_GAS_MARGIN = 0.2

src/hooks/usePermitAllowance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { signTypedData } from '@uniswap/conedison/provider'
1+
import { signTypedData } from '@uniswap/conedison/provider/signing'
22
import { AllowanceTransfer, MaxAllowanceTransferAmount, PERMIT2_ADDRESS, PermitSingle } from '@uniswap/permit2-sdk'
33
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
44
import { useWeb3React } from '@web3-react/core'

src/hooks/useUniversalRouter.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { BigNumber } from '@ethersproject/bignumber'
22
import { TransactionRequest, TransactionResponse } from '@ethersproject/providers'
33
import { t } from '@lingui/macro'
4+
import { sendTransaction } from '@uniswap/conedison/provider/index'
45
import { Percent } from '@uniswap/sdk-core'
56
import { SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
67
import { FeeOptions, toHex } from '@uniswap/v3-sdk'
78
import { useWeb3React } from '@web3-react/core'
89
import { ErrorCode } from 'constants/eip1193'
10+
import { TX_GAS_MARGIN } from 'constants/misc'
911
import { SwapError } from 'errors'
1012
import { useCallback } from 'react'
1113
import { InterfaceTrade } from 'state/routing/types'
12-
import { calculateGasMargin } from 'utils/calculateGasMargin'
1314
import isZero from 'utils/isZero'
1415
import { getReason, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage'
1516

@@ -68,15 +69,7 @@ export function useUniversalRouterSwapCallback(trade: InterfaceTrade | undefined
6869
...(value && !isZero(value) ? { value: toHex(value) } : {}),
6970
}
7071

71-
let gasEstimate: BigNumber
72-
try {
73-
gasEstimate = await provider.estimateGas(tx)
74-
} catch (gasError) {
75-
console.warn(gasError)
76-
throw new SwapError({ header: t`Swap Error`, message: t`Your swap is expected to fail` })
77-
}
78-
const gasLimit = calculateGasMargin(gasEstimate)
79-
response = await provider.getSigner().sendTransaction({ ...tx, gasLimit })
72+
response = await sendTransaction(provider, tx, TX_GAS_MARGIN)
8073
} catch (swapError) {
8174
if (didUserReject(swapError)) {
8275
return null

test/setup-jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jest.mock('@uniswap/conedison/format', () => ({
1818
const MOCK_TYPED_DATA_SIG =
1919
'0x1befd08fcc4085dc484346d69fd15659616522454a33e66e7b0f6917379ab888236304ebed307813208bf004da04d998dcd15a8f83241d033e4040adc4b0b5311b'
2020

21-
jest.mock('@uniswap/conedison/provider', () => ({
21+
jest.mock('@uniswap/conedison/provider/signing', () => ({
2222
signTypedData: () => Promise.resolve(MOCK_TYPED_DATA_SIG),
2323
}))
2424

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,10 +3518,10 @@
35183518
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
35193519
integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==
35203520

3521-
"@uniswap/conedison@^1.3.0":
3522-
version "1.3.0"
3523-
resolved "https://registry.yarnpkg.com/@uniswap/conedison/-/conedison-1.3.0.tgz#998aca2bad27f0780a05b40e4512acfcadfece79"
3524-
integrity sha512-zpZ52svBJ2btwl09mLOw7HlBxFDuYAjAZXLAR7WQZJeRgjD1yD2QuI3v7JliXvHzJh3ePYH6820EMp7xQbdAGQ==
3521+
"@uniswap/conedison@^1.5.1":
3522+
version "1.5.1"
3523+
resolved "https://registry.yarnpkg.com/@uniswap/conedison/-/conedison-1.5.1.tgz#91527cc9928ce0187f30a5eb4abb705b8f0cd013"
3524+
integrity sha512-VJqUW4l54QVj5a4vAzAlWWd193iCcT8HMugFPB28S2Uqhs2elAg/RDQmiPOf9TOFB635MdBlD0S6xUuqo7FB4A==
35253525

35263526
"@uniswap/default-token-list@^2.0.0":
35273527
version "2.2.0"

0 commit comments

Comments
 (0)