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() {
...
@@ -107,6 +107,8 @@ export function useSyncWidgetTransactions() {
const
eventProperties
=
{
const
eventProperties
=
{
...
formatSwapSignedAnalyticsEventProperties
({
...
formatSwapSignedAnalyticsEventProperties
({
trade
,
trade
,
// TODO: add once Widgets adds fiat values to callback
fiatValues
:
{
amountIn
:
null
,
amountOut
:
null
},
txHash
:
transaction
.
receipt
?.
transactionHash
??
''
,
txHash
:
transaction
.
receipt
?.
transactionHash
??
''
,
}),
}),
...
trace
,
...
trace
,
...
...
src/hooks/useSwapCallback.tsx
View file @
b721824c
import
{
Trade
}
from
'
@uniswap/router-sdk
'
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
{
PermitSignature
}
from
'
hooks/usePermitAllowance
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
...
@@ -13,6 +13,7 @@ import { useUniversalRouterSwapCallback } from './useUniversalRouter'
...
@@ -13,6 +13,7 @@ import { useUniversalRouterSwapCallback } from './useUniversalRouter'
// and the user has approved the slippage adjusted input amount for the trade
// and the user has approved the slippage adjusted input amount for the trade
export
function
useSwapCallback
(
export
function
useSwapCallback
(
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
|
undefined
,
// trade to execute, required
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
allowedSlippage
:
Percent
,
// in bips
permitSignature
:
PermitSignature
|
undefined
permitSignature
:
PermitSignature
|
undefined
):
{
callback
:
null
|
(()
=>
Promise
<
string
>
)
}
{
):
{
callback
:
null
|
(()
=>
Promise
<
string
>
)
}
{
...
@@ -20,7 +21,7 @@ export function useSwapCallback(
...
@@ -20,7 +21,7 @@ export function useSwapCallback(
const
addTransaction
=
useTransactionAdder
()
const
addTransaction
=
useTransactionAdder
()
const
universalRouterSwapCallback
=
useUniversalRouterSwapCallback
(
trade
,
{
const
universalRouterSwapCallback
=
useUniversalRouterSwapCallback
(
trade
,
fiatValues
,
{
slippageTolerance
:
allowedSlippage
,
slippageTolerance
:
allowedSlippage
,
deadline
,
deadline
,
permit
:
permitSignature
,
permit
:
permitSignature
,
...
...
src/hooks/useUniversalRouter.ts
View file @
b721824c
...
@@ -4,7 +4,7 @@ import { t } from '@lingui/macro'
...
@@ -4,7 +4,7 @@ import { t } from '@lingui/macro'
import
{
sendAnalyticsEvent
}
from
'
@uniswap/analytics
'
import
{
sendAnalyticsEvent
}
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
,
CurrencyAmount
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
SwapRouter
,
UNIVERSAL_ROUTER_ADDRESS
}
from
'
@uniswap/universal-router-sdk
'
import
{
SwapRouter
,
UNIVERSAL_ROUTER_ADDRESS
}
from
'
@uniswap/universal-router-sdk
'
import
{
FeeOptions
,
toHex
}
from
'
@uniswap/v3-sdk
'
import
{
FeeOptions
,
toHex
}
from
'
@uniswap/v3-sdk
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
...
@@ -27,6 +27,7 @@ interface SwapOptions {
...
@@ -27,6 +27,7 @@ interface SwapOptions {
export
function
useUniversalRouterSwapCallback
(
export
function
useUniversalRouterSwapCallback
(
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
|
undefined
,
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
|
undefined
,
fiatValues
:
{
amountIn
:
CurrencyAmount
<
Currency
>
|
null
;
amountOut
:
CurrencyAmount
<
Currency
>
|
null
},
options
:
SwapOptions
options
:
SwapOptions
)
{
)
{
const
{
account
,
chainId
,
provider
}
=
useWeb3React
()
const
{
account
,
chainId
,
provider
}
=
useWeb3React
()
...
@@ -66,7 +67,7 @@ export function useUniversalRouterSwapCallback(
...
@@ -66,7 +67,7 @@ export function useUniversalRouterSwapCallback(
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
sendAnalyticsEvent
(
sendAnalyticsEvent
(
SwapEventName
.
SWAP_SIGNED
,
SwapEventName
.
SWAP_SIGNED
,
formatSwapSignedAnalyticsEventProperties
({
trade
,
txHash
:
response
.
hash
})
formatSwapSignedAnalyticsEventProperties
({
trade
,
fiatValues
,
txHash
:
response
.
hash
})
)
)
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
})
...
@@ -84,6 +85,7 @@ export function useUniversalRouterSwapCallback(
...
@@ -84,6 +85,7 @@ export function useUniversalRouterSwapCallback(
},
[
},
[
account
,
account
,
chainId
,
chainId
,
fiatValues
,
options
.
deadline
,
options
.
deadline
,
options
.
feeOptions
,
options
.
feeOptions
,
options
.
permit
,
options
.
permit
,
...
...
src/lib/utils/analytics.ts
View file @
b721824c
...
@@ -36,9 +36,11 @@ export const getPriceUpdateBasisPoints = (
...
@@ -36,9 +36,11 @@ export const getPriceUpdateBasisPoints = (
export
const
formatSwapSignedAnalyticsEventProperties
=
({
export
const
formatSwapSignedAnalyticsEventProperties
=
({
trade
,
trade
,
fiatValues
,
txHash
,
txHash
,
}:
{
}:
{
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
|
Trade
<
Currency
,
Currency
,
TradeType
>
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
|
Trade
<
Currency
,
Currency
,
TradeType
>
fiatValues
:
{
amountIn
:
CurrencyAmount
<
Currency
>
|
null
;
amountOut
:
CurrencyAmount
<
Currency
>
|
null
}
txHash
:
string
txHash
:
string
})
=>
({
})
=>
({
transaction_hash
:
txHash
,
transaction_hash
:
txHash
,
...
@@ -48,6 +50,8 @@ export const formatSwapSignedAnalyticsEventProperties = ({
...
@@ -48,6 +50,8 @@ export const formatSwapSignedAnalyticsEventProperties = ({
token_out_symbol
:
trade
.
outputAmount
.
currency
.
symbol
,
token_out_symbol
:
trade
.
outputAmount
.
currency
.
symbol
,
token_in_amount
:
formatToDecimal
(
trade
.
inputAmount
,
trade
.
inputAmount
.
currency
.
decimals
),
token_in_amount
:
formatToDecimal
(
trade
.
inputAmount
,
trade
.
inputAmount
.
currency
.
decimals
),
token_out_amount
:
formatToDecimal
(
trade
.
outputAmount
,
trade
.
outputAmount
.
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
)),
price_impact_basis_points
:
formatPercentInBasisPointsNumber
(
computeRealizedPriceImpact
(
trade
)),
chain_id
:
chain_id
:
trade
.
inputAmount
.
currency
.
chainId
===
trade
.
outputAmount
.
currency
.
chainId
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 }) {
...
@@ -333,10 +333,14 @@ export default function Swap({ className }: { className?: string }) {
[
currencyBalances
]
[
currencyBalances
]
)
)
const
showMaxButton
=
Boolean
(
maxInputAmount
?.
greaterThan
(
0
)
&&
!
parsedAmounts
[
Field
.
INPUT
]?.
equalTo
(
maxInputAmount
))
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
// the callback to execute the swap
const
{
callback
:
swapCallback
}
=
useSwapCallback
(
const
{
callback
:
swapCallback
}
=
useSwapCallback
(
trade
,
trade
,
swapFiatValues
,
allowedSlippage
,
allowedSlippage
,
allowance
.
state
===
AllowanceState
.
ALLOWED
?
allowance
.
permitSignature
:
undefined
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