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
b721824c
Unverified
Commit
b721824c
authored
Mar 09, 2023
by
Tina
Committed by
GitHub
Mar 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add USD amounts to swap analytics (#6108)
parent
2451a5c9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
4 deletions
+17
-4
transactions.ts
src/components/Widget/transactions.ts
+2
-0
useSwapCallback.tsx
src/hooks/useSwapCallback.tsx
+3
-2
useUniversalRouter.ts
src/hooks/useUniversalRouter.ts
+4
-2
analytics.ts
src/lib/utils/analytics.ts
+4
-0
index.tsx
src/pages/Swap/index.tsx
+4
-0
No files found.
src/components/Widget/transactions.ts
View file @
b721824c
...
...
@@ -107,6 +107,8 @@ export function useSyncWidgetTransactions() {
const
eventProperties
=
{
...
formatSwapSignedAnalyticsEventProperties
({
trade
,
// TODO: add once Widgets adds fiat values to callback
fiatValues
:
{
amountIn
:
null
,
amountOut
:
null
},
txHash
:
transaction
.
receipt
?.
transactionHash
??
''
,
}),
...
trace
,
...
...
src/hooks/useSwapCallback.tsx
View file @
b721824c
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
Currency
,
CurrencyAmount
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
PermitSignature
}
from
'
hooks/usePermitAllowance
'
import
{
useMemo
}
from
'
react
'
...
...
@@ -13,6 +13,7 @@ import { useUniversalRouterSwapCallback } from './useUniversalRouter'
// and the user has approved the slippage adjusted input amount for the trade
export
function
useSwapCallback
(
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
|
undefined
,
// trade to execute, required
fiatValues
:
{
amountIn
:
CurrencyAmount
<
Currency
>
|
null
;
amountOut
:
CurrencyAmount
<
Currency
>
|
null
},
// usd values for amount in and out, logged for analytics
allowedSlippage
:
Percent
,
// in bips
permitSignature
:
PermitSignature
|
undefined
):
{
callback
:
null
|
(()
=>
Promise
<
string
>
)
}
{
...
...
@@ -20,7 +21,7 @@ export function useSwapCallback(
const
addTransaction
=
useTransactionAdder
()
const
universalRouterSwapCallback
=
useUniversalRouterSwapCallback
(
trade
,
{
const
universalRouterSwapCallback
=
useUniversalRouterSwapCallback
(
trade
,
fiatValues
,
{
slippageTolerance
:
allowedSlippage
,
deadline
,
permit
:
permitSignature
,
...
...
src/hooks/useUniversalRouter.ts
View file @
b721824c
...
...
@@ -4,7 +4,7 @@ import { t } from '@lingui/macro'
import
{
sendAnalyticsEvent
}
from
'
@uniswap/analytics
'
import
{
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
Currency
,
CurrencyAmount
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
SwapRouter
,
UNIVERSAL_ROUTER_ADDRESS
}
from
'
@uniswap/universal-router-sdk
'
import
{
FeeOptions
,
toHex
}
from
'
@uniswap/v3-sdk
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
...
...
@@ -27,6 +27,7 @@ interface SwapOptions {
export
function
useUniversalRouterSwapCallback
(
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
|
undefined
,
fiatValues
:
{
amountIn
:
CurrencyAmount
<
Currency
>
|
null
;
amountOut
:
CurrencyAmount
<
Currency
>
|
null
},
options
:
SwapOptions
)
{
const
{
account
,
chainId
,
provider
}
=
useWeb3React
()
...
...
@@ -66,7 +67,7 @@ export function useUniversalRouterSwapCallback(
.
then
((
response
)
=>
{
sendAnalyticsEvent
(
SwapEventName
.
SWAP_SIGNED
,
formatSwapSignedAnalyticsEventProperties
({
trade
,
txHash
:
response
.
hash
})
formatSwapSignedAnalyticsEventProperties
({
trade
,
fiatValues
,
txHash
:
response
.
hash
})
)
if
(
tx
.
data
!==
response
.
data
)
{
sendAnalyticsEvent
(
SwapEventName
.
SWAP_MODIFIED_IN_WALLET
,
{
txHash
:
response
.
hash
})
...
...
@@ -84,6 +85,7 @@ export function useUniversalRouterSwapCallback(
},
[
account
,
chainId
,
fiatValues
,
options
.
deadline
,
options
.
feeOptions
,
options
.
permit
,
...
...
src/lib/utils/analytics.ts
View file @
b721824c
...
...
@@ -36,9 +36,11 @@ export const getPriceUpdateBasisPoints = (
export
const
formatSwapSignedAnalyticsEventProperties
=
({
trade
,
fiatValues
,
txHash
,
}:
{
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
|
Trade
<
Currency
,
Currency
,
TradeType
>
fiatValues
:
{
amountIn
:
CurrencyAmount
<
Currency
>
|
null
;
amountOut
:
CurrencyAmount
<
Currency
>
|
null
}
txHash
:
string
})
=>
({
transaction_hash
:
txHash
,
...
...
@@ -48,6 +50,8 @@ export const formatSwapSignedAnalyticsEventProperties = ({
token_out_symbol
:
trade
.
outputAmount
.
currency
.
symbol
,
token_in_amount
:
formatToDecimal
(
trade
.
inputAmount
,
trade
.
inputAmount
.
currency
.
decimals
),
token_out_amount
:
formatToDecimal
(
trade
.
outputAmount
,
trade
.
outputAmount
.
currency
.
decimals
),
token_in_amount_usd
:
fiatValues
.
amountIn
?
parseFloat
(
fiatValues
.
amountIn
.
toFixed
(
2
))
:
undefined
,
token_out_amount_usd
:
fiatValues
.
amountOut
?
parseFloat
(
fiatValues
.
amountOut
.
toFixed
(
2
))
:
undefined
,
price_impact_basis_points
:
formatPercentInBasisPointsNumber
(
computeRealizedPriceImpact
(
trade
)),
chain_id
:
trade
.
inputAmount
.
currency
.
chainId
===
trade
.
outputAmount
.
currency
.
chainId
...
...
src/pages/Swap/index.tsx
View file @
b721824c
...
...
@@ -333,10 +333,14 @@ export default function Swap({ className }: { className?: string }) {
[
currencyBalances
]
)
const
showMaxButton
=
Boolean
(
maxInputAmount
?.
greaterThan
(
0
)
&&
!
parsedAmounts
[
Field
.
INPUT
]?.
equalTo
(
maxInputAmount
))
const
swapFiatValues
=
useMemo
(()
=>
{
return
{
amountIn
:
fiatValueTradeInput
,
amountOut
:
fiatValueTradeOutput
}
},
[
fiatValueTradeInput
,
fiatValueTradeOutput
])
// the callback to execute the swap
const
{
callback
:
swapCallback
}
=
useSwapCallback
(
trade
,
swapFiatValues
,
allowedSlippage
,
allowance
.
state
===
AllowanceState
.
ALLOWED
?
allowance
.
permitSignature
:
undefined
)
...
...
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