Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
c8a81491
Unverified
Commit
c8a81491
authored
May 04, 2023
by
eddie
Committed by
GitHub
May 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: add amplitude page context to swap flow events (#6489)
parent
38cde648
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
useUniversalRouter.ts
src/hooks/useUniversalRouter.ts
+15
-6
index.tsx
src/pages/Swap/index.tsx
+13
-6
No files found.
src/hooks/useUniversalRouter.ts
View file @
c8a81491
import
{
TransactionResponse
}
from
'
@ethersproject/abstract-provider
'
import
{
TransactionResponse
}
from
'
@ethersproject/abstract-provider
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
t
}
from
'
@lingui/macro
'
import
{
t
}
from
'
@lingui/macro
'
import
{
sendAnalyticsEvent
}
from
'
@uniswap/analytics
'
import
{
sendAnalyticsEvent
,
useTrace
}
from
'
@uniswap/analytics
'
import
{
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
...
@@ -49,6 +49,7 @@ export function useUniversalRouterSwapCallback(
...
@@ -49,6 +49,7 @@ export function useUniversalRouterSwapCallback(
options
:
SwapOptions
options
:
SwapOptions
)
{
)
{
const
{
account
,
chainId
,
provider
}
=
useWeb3React
()
const
{
account
,
chainId
,
provider
}
=
useWeb3React
()
const
analyticsContext
=
useTrace
()
return
useCallback
(
async
():
Promise
<
TransactionResponse
>
=>
{
return
useCallback
(
async
():
Promise
<
TransactionResponse
>
=>
{
return
trace
(
return
trace
(
...
@@ -90,12 +91,19 @@ export function useUniversalRouterSwapCallback(
...
@@ -90,12 +91,19 @@ export function useUniversalRouterSwapCallback(
.
getSigner
()
.
getSigner
()
.
sendTransaction
({
...
tx
,
gasLimit
})
.
sendTransaction
({
...
tx
,
gasLimit
})
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
sendAnalyticsEvent
(
sendAnalyticsEvent
(
SwapEventName
.
SWAP_SIGNED
,
{
SwapEventName
.
SWAP_SIGNED
,
...
formatSwapSignedAnalyticsEventProperties
({
formatSwapSignedAnalyticsEventProperties
({
trade
,
fiatValues
,
txHash
:
response
.
hash
})
trade
,
)
fiatValues
,
txHash
:
response
.
hash
,
}),
...
analyticsContext
,
})
if
(
tx
.
data
!==
response
.
data
)
{
if
(
tx
.
data
!==
response
.
data
)
{
sendAnalyticsEvent
(
SwapEventName
.
SWAP_MODIFIED_IN_WALLET
,
{
txHash
:
response
.
hash
})
sendAnalyticsEvent
(
SwapEventName
.
SWAP_MODIFIED_IN_WALLET
,
{
txHash
:
response
.
hash
,
...
analyticsContext
,
})
throw
new
ModifiedSwapError
()
throw
new
ModifiedSwapError
()
}
}
return
response
return
response
...
@@ -117,6 +125,7 @@ export function useUniversalRouterSwapCallback(
...
@@ -117,6 +125,7 @@ export function useUniversalRouterSwapCallback(
)
)
},
[
},
[
account
,
account
,
analyticsContext
,
chainId
,
chainId
,
fiatValues
,
fiatValues
,
options
.
deadline
,
options
.
deadline
,
...
...
src/pages/Swap/index.tsx
View file @
c8a81491
import
{
Trans
}
from
'
@lingui/macro
'
import
{
Trans
}
from
'
@lingui/macro
'
import
{
sendAnalyticsEvent
,
Trace
,
TraceEvent
}
from
'
@uniswap/analytics
'
import
{
sendAnalyticsEvent
,
Trace
,
TraceEvent
,
useTrace
}
from
'
@uniswap/analytics
'
import
{
import
{
BrowserEvent
,
BrowserEvent
,
InterfaceElementName
,
InterfaceElementName
,
...
@@ -189,6 +189,7 @@ export function Swap({
...
@@ -189,6 +189,7 @@ export function Swap({
const
{
account
,
chainId
:
connectedChainId
,
connector
}
=
useWeb3React
()
const
{
account
,
chainId
:
connectedChainId
,
connector
}
=
useWeb3React
()
const
[
newSwapQuoteNeedsLogging
,
setNewSwapQuoteNeedsLogging
]
=
useState
(
true
)
const
[
newSwapQuoteNeedsLogging
,
setNewSwapQuoteNeedsLogging
]
=
useState
(
true
)
const
[
fetchingSwapQuoteStartTime
,
setFetchingSwapQuoteStartTime
]
=
useState
<
Date
|
undefined
>
()
const
[
fetchingSwapQuoteStartTime
,
setFetchingSwapQuoteStartTime
]
=
useState
<
Date
|
undefined
>
()
const
trace
=
useTrace
()
// token warning stuff
// token warning stuff
const
prefilledInputCurrency
=
useCurrency
(
prefilledState
?.[
Field
.
INPUT
]?.
currencyId
)
const
prefilledInputCurrency
=
useCurrency
(
prefilledState
?.[
Field
.
INPUT
]?.
currencyId
)
...
@@ -392,13 +393,14 @@ export function Swap({
...
@@ -392,13 +393,14 @@ export function Swap({
chain_id
:
chainId
,
chain_id
:
chainId
,
token_symbol
:
maximumAmountIn
?.
currency
.
symbol
,
token_symbol
:
maximumAmountIn
?.
currency
.
symbol
,
token_address
:
maximumAmountIn
?.
currency
.
address
,
token_address
:
maximumAmountIn
?.
currency
.
address
,
...
trace
,
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
e
)
console
.
error
(
e
)
}
finally
{
}
finally
{
setIsAllowancePending
(
false
)
setIsAllowancePending
(
false
)
}
}
},
[
allowance
,
chainId
,
maximumAmountIn
?.
currency
.
address
,
maximumAmountIn
?.
currency
.
symbol
])
},
[
allowance
,
chainId
,
maximumAmountIn
?.
currency
.
address
,
maximumAmountIn
?.
currency
.
symbol
,
trace
])
const
maxInputAmount
:
CurrencyAmount
<
Currency
>
|
undefined
=
useMemo
(
const
maxInputAmount
:
CurrencyAmount
<
Currency
>
|
undefined
=
useMemo
(
()
=>
maxAmountSpend
(
currencyBalances
[
Field
.
INPUT
]),
()
=>
maxAmountSpend
(
currencyBalances
[
Field
.
INPUT
]),
...
@@ -534,10 +536,14 @@ export function Swap({
...
@@ -534,10 +536,14 @@ export function Swap({
// Set the current datetime as the time of receipt of latest swap quote.
// Set the current datetime as the time of receipt of latest swap quote.
setSwapQuoteReceivedDate
(
now
)
setSwapQuoteReceivedDate
(
now
)
// Log swap quote.
// Log swap quote.
sendAnalyticsEvent
(
sendAnalyticsEvent
(
SwapEventName
.
SWAP_QUOTE_RECEIVED
,
{
SwapEventName
.
SWAP_QUOTE_RECEIVED
,
...
formatSwapQuoteReceivedEventProperties
(
formatSwapQuoteReceivedEventProperties
(
trade
,
trade
.
gasUseEstimateUSD
??
undefined
,
fetchingSwapQuoteStartTime
)
trade
,
)
trade
.
gasUseEstimateUSD
??
undefined
,
fetchingSwapQuoteStartTime
),
...
trace
,
})
// Latest swap quote has just been logged, so we don't need to log the current trade anymore
// Latest swap quote has just been logged, so we don't need to log the current trade anymore
// unless user inputs change again and a new trade is in the process of being generated.
// unless user inputs change again and a new trade is in the process of being generated.
setNewSwapQuoteNeedsLogging
(
false
)
setNewSwapQuoteNeedsLogging
(
false
)
...
@@ -556,6 +562,7 @@ export function Swap({
...
@@ -556,6 +562,7 @@ export function Swap({
fetchingSwapQuoteStartTime
,
fetchingSwapQuoteStartTime
,
trade
,
trade
,
setSwapQuoteReceivedDate
,
setSwapQuoteReceivedDate
,
trace
,
])
])
const
showDetailsDropdown
=
Boolean
(
const
showDetailsDropdown
=
Boolean
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment