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
eb4f90e6
Unverified
Commit
eb4f90e6
authored
Aug 26, 2022
by
lynn
Committed by
GitHub
Aug 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add volume trade info to swap completed event (#4506)
add volume trade info to swap completed event
parent
40308158
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
13 deletions
+70
-13
ConfirmSwapModal.tsx
src/components/swap/ConfirmSwapModal.tsx
+1
-1
SwapModalFooter.tsx
src/components/swap/SwapModalFooter.tsx
+6
-6
updater.tsx
src/state/transactions/updater.tsx
+63
-6
No files found.
src/components/swap/ConfirmSwapModal.tsx
View file @
eb4f90e6
...
@@ -73,7 +73,7 @@ export default function ConfirmSwapModal({
...
@@ -73,7 +73,7 @@ export default function ConfirmSwapModal({
<
SwapModalFooter
<
SwapModalFooter
onConfirm=
{
onConfirm
}
onConfirm=
{
onConfirm
}
trade=
{
trade
}
trade=
{
trade
}
txH
ash=
{
txHash
}
h
ash=
{
txHash
}
allowedSlippage=
{
allowedSlippage
}
allowedSlippage=
{
allowedSlippage
}
disabledConfirm=
{
showAcceptChanges
}
disabledConfirm=
{
showAcceptChanges
}
swapErrorMessage=
{
swapErrorMessage
}
swapErrorMessage=
{
swapErrorMessage
}
...
...
src/components/swap/SwapModalFooter.tsx
View file @
eb4f90e6
...
@@ -25,7 +25,7 @@ import { getTokenPath, RoutingDiagramEntry } from './SwapRoute'
...
@@ -25,7 +25,7 @@ import { getTokenPath, RoutingDiagramEntry } from './SwapRoute'
interface
AnalyticsEventProps
{
interface
AnalyticsEventProps
{
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
txH
ash
:
string
|
undefined
h
ash
:
string
|
undefined
allowedSlippage
:
Percent
allowedSlippage
:
Percent
transactionDeadlineSecondsSinceEpoch
:
number
|
undefined
transactionDeadlineSecondsSinceEpoch
:
number
|
undefined
isAutoSlippage
:
boolean
isAutoSlippage
:
boolean
...
@@ -65,7 +65,7 @@ const formatRoutesEventProperties = (routes: RoutingDiagramEntry[]) => {
...
@@ -65,7 +65,7 @@ const formatRoutesEventProperties = (routes: RoutingDiagramEntry[]) => {
const
formatAnalyticsEventProperties
=
({
const
formatAnalyticsEventProperties
=
({
trade
,
trade
,
txH
ash
,
h
ash
,
allowedSlippage
,
allowedSlippage
,
transactionDeadlineSecondsSinceEpoch
,
transactionDeadlineSecondsSinceEpoch
,
isAutoSlippage
,
isAutoSlippage
,
...
@@ -76,7 +76,7 @@ const formatAnalyticsEventProperties = ({
...
@@ -76,7 +76,7 @@ const formatAnalyticsEventProperties = ({
routes
,
routes
,
}:
AnalyticsEventProps
)
=>
({
}:
AnalyticsEventProps
)
=>
({
estimated_network_fee_usd
:
trade
.
gasUseEstimateUSD
?
formatToDecimal
(
trade
.
gasUseEstimateUSD
,
2
)
:
undefined
,
estimated_network_fee_usd
:
trade
.
gasUseEstimateUSD
?
formatToDecimal
(
trade
.
gasUseEstimateUSD
,
2
)
:
undefined
,
transaction_hash
:
txH
ash
,
transaction_hash
:
h
ash
,
transaction_deadline_seconds
:
getDurationUntilTimestampSeconds
(
transactionDeadlineSecondsSinceEpoch
),
transaction_deadline_seconds
:
getDurationUntilTimestampSeconds
(
transactionDeadlineSecondsSinceEpoch
),
token_in_amount_usd
:
tokenInAmountUsd
?
parseFloat
(
tokenInAmountUsd
)
:
undefined
,
token_in_amount_usd
:
tokenInAmountUsd
?
parseFloat
(
tokenInAmountUsd
)
:
undefined
,
token_out_amount_usd
:
tokenOutAmountUsd
?
parseFloat
(
tokenOutAmountUsd
)
:
undefined
,
token_out_amount_usd
:
tokenOutAmountUsd
?
parseFloat
(
tokenOutAmountUsd
)
:
undefined
,
...
@@ -104,14 +104,14 @@ const formatAnalyticsEventProperties = ({
...
@@ -104,14 +104,14 @@ const formatAnalyticsEventProperties = ({
export
default
function
SwapModalFooter
({
export
default
function
SwapModalFooter
({
trade
,
trade
,
allowedSlippage
,
allowedSlippage
,
txH
ash
,
h
ash
,
onConfirm
,
onConfirm
,
swapErrorMessage
,
swapErrorMessage
,
disabledConfirm
,
disabledConfirm
,
swapQuoteReceivedDate
,
swapQuoteReceivedDate
,
}:
{
}:
{
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
txH
ash
:
string
|
undefined
h
ash
:
string
|
undefined
allowedSlippage
:
Percent
allowedSlippage
:
Percent
onConfirm
:
()
=>
void
onConfirm
:
()
=>
void
swapErrorMessage
:
ReactNode
|
undefined
swapErrorMessage
:
ReactNode
|
undefined
...
@@ -134,7 +134,7 @@ export default function SwapModalFooter({
...
@@ -134,7 +134,7 @@ export default function SwapModalFooter({
name=
{
EventName
.
SWAP_SUBMITTED
}
name=
{
EventName
.
SWAP_SUBMITTED
}
properties=
{
formatAnalyticsEventProperties
({
properties=
{
formatAnalyticsEventProperties
({
trade
,
trade
,
txH
ash
,
h
ash
,
allowedSlippage
,
allowedSlippage
,
transactionDeadlineSecondsSinceEpoch
,
transactionDeadlineSecondsSinceEpoch
,
isAutoSlippage
,
isAutoSlippage
,
...
...
src/state/transactions/updater.tsx
View file @
eb4f90e6
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
sendAnalyticsEvent
}
from
'
components/AmplitudeAnalytics
'
import
{
sendAnalyticsEvent
}
from
'
components/AmplitudeAnalytics
'
import
{
EventName
}
from
'
components/AmplitudeAnalytics/constants
'
import
{
EventName
}
from
'
components/AmplitudeAnalytics/constants
'
import
{
formatPercentInBasisPointsNumber
,
formatToDecimal
,
getTokenAddress
}
from
'
components/AmplitudeAnalytics/utils
'
import
{
DEFAULT_TXN_DISMISS_MS
,
L2_TXN_DISMISS_MS
}
from
'
constants/misc
'
import
{
DEFAULT_TXN_DISMISS_MS
,
L2_TXN_DISMISS_MS
}
from
'
constants/misc
'
import
{
useStablecoinValue
}
from
'
hooks/useStablecoinPrice
'
import
LibUpdater
from
'
lib/hooks/transactions/updater
'
import
LibUpdater
from
'
lib/hooks/transactions/updater
'
import
{
useCallback
,
useMemo
}
from
'
react
'
import
{
useCallback
,
useMemo
}
from
'
react
'
import
{
useAppDispatch
,
useAppSelector
}
from
'
state/hooks
'
import
{
useAppDispatch
,
useAppSelector
}
from
'
state/hooks
'
import
{
InterfaceTrade
}
from
'
state/routing/types
'
import
{
TransactionType
}
from
'
state/transactions/types
'
import
{
TransactionType
}
from
'
state/transactions/types
'
import
{
computeRealizedPriceImpact
}
from
'
utils/prices
'
import
{
L2_CHAIN_IDS
}
from
'
../../constants/chains
'
import
{
L2_CHAIN_IDS
}
from
'
../../constants/chains
'
import
{
useDerivedSwapInfo
}
from
'
../../state/swap/hooks
'
import
{
useAddPopup
}
from
'
../application/hooks
'
import
{
useAddPopup
}
from
'
../application/hooks
'
import
{
checkedTransaction
,
finalizeTransaction
}
from
'
./reducer
'
import
{
checkedTransaction
,
finalizeTransaction
}
from
'
./reducer
'
import
{
SerializableTransactionReceipt
}
from
'
./types
'
import
{
SerializableTransactionReceipt
}
from
'
./types
'
interface
AnalyticsEventProps
{
trade
:
InterfaceTrade
<
Currency
,
Currency
,
TradeType
>
hash
:
string
|
undefined
allowedSlippage
:
Percent
tokenInAmountUsd
:
string
|
undefined
tokenOutAmountUsd
:
string
|
undefined
succeeded
:
boolean
}
const
formatAnalyticsEventProperties
=
({
trade
,
hash
,
allowedSlippage
,
tokenInAmountUsd
,
tokenOutAmountUsd
,
succeeded
,
}:
AnalyticsEventProps
)
=>
({
estimated_network_fee_usd
:
trade
.
gasUseEstimateUSD
?
formatToDecimal
(
trade
.
gasUseEstimateUSD
,
2
)
:
undefined
,
transaction_hash
:
hash
,
token_in_amount_usd
:
tokenInAmountUsd
?
parseFloat
(
tokenInAmountUsd
)
:
undefined
,
token_out_amount_usd
:
tokenOutAmountUsd
?
parseFloat
(
tokenOutAmountUsd
)
:
undefined
,
token_in_address
:
getTokenAddress
(
trade
.
inputAmount
.
currency
),
token_out_address
:
getTokenAddress
(
trade
.
outputAmount
.
currency
),
token_in_symbol
:
trade
.
inputAmount
.
currency
.
symbol
,
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
),
price_impact_basis_points
:
formatPercentInBasisPointsNumber
(
computeRealizedPriceImpact
(
trade
)),
allowed_slippage_basis_points
:
formatPercentInBasisPointsNumber
(
allowedSlippage
),
chain_id
:
trade
.
inputAmount
.
currency
.
chainId
===
trade
.
outputAmount
.
currency
.
chainId
?
trade
.
inputAmount
.
currency
.
chainId
:
undefined
,
swap_quote_block_number
:
trade
.
blockNumber
,
succeeded
,
})
export
default
function
Updater
()
{
export
default
function
Updater
()
{
const
{
chainId
}
=
useWeb3React
()
const
{
chainId
}
=
useWeb3React
()
const
addPopup
=
useAddPopup
()
const
addPopup
=
useAddPopup
()
// speed up popup dismisall time if on L2
// speed up popup dismisall time if on L2
const
isL2
=
Boolean
(
chainId
&&
L2_CHAIN_IDS
.
includes
(
chainId
))
const
isL2
=
Boolean
(
chainId
&&
L2_CHAIN_IDS
.
includes
(
chainId
))
const
transactions
=
useAppSelector
((
state
)
=>
state
.
transactions
)
const
transactions
=
useAppSelector
((
state
)
=>
state
.
transactions
)
const
{
trade
:
{
trade
},
allowedSlippage
,
}
=
useDerivedSwapInfo
()
const
tokenInAmountUsd
=
useStablecoinValue
(
trade
?.
inputAmount
)?.
toFixed
(
2
)
const
tokenOutAmountUsd
=
useStablecoinValue
(
trade
?.
outputAmount
)?.
toFixed
(
2
)
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
const
onCheck
=
useCallback
(
const
onCheck
=
useCallback
(
...
@@ -44,11 +93,19 @@ export default function Updater() {
...
@@ -44,11 +93,19 @@ export default function Updater() {
})
})
)
)
const
tx
=
transactions
[
chainId
]?.[
hash
]
const
tx
=
transactions
[
chainId
]?.[
hash
]
if
(
tx
.
info
.
type
===
TransactionType
.
SWAP
)
{
sendAnalyticsEvent
(
EventName
.
SWAP_TRANSACTION_COMPLETED
,
{
if
(
tx
.
info
.
type
===
TransactionType
.
SWAP
&&
trade
)
{
transaction_hash
:
tx
.
hash
,
sendAnalyticsEvent
(
succeeded
:
receipt
.
status
===
1
,
EventName
.
SWAP_TRANSACTION_COMPLETED
,
})
formatAnalyticsEventProperties
({
trade
,
hash
,
allowedSlippage
,
tokenInAmountUsd
,
tokenOutAmountUsd
,
succeeded
:
receipt
.
status
===
1
,
})
)
}
}
addPopup
(
addPopup
(
{
{
...
@@ -58,7 +115,7 @@ export default function Updater() {
...
@@ -58,7 +115,7 @@ export default function Updater() {
isL2
?
L2_TXN_DISMISS_MS
:
DEFAULT_TXN_DISMISS_MS
isL2
?
L2_TXN_DISMISS_MS
:
DEFAULT_TXN_DISMISS_MS
)
)
},
},
[
addPopup
,
dispatch
,
isL2
,
transactions
]
[
addPopup
,
allowedSlippage
,
dispatch
,
isL2
,
tokenInAmountUsd
,
tokenOutAmountUsd
,
trade
,
transactions
]
)
)
const
pendingTransactions
=
useMemo
(()
=>
(
chainId
?
transactions
[
chainId
]
??
{}
:
{}),
[
chainId
,
transactions
])
const
pendingTransactions
=
useMemo
(()
=>
(
chainId
?
transactions
[
chainId
]
??
{}
:
{}),
[
chainId
,
transactions
])
...
...
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