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
db6084d7
Unverified
Commit
db6084d7
authored
Feb 03, 2023
by
eddie
Committed by
GitHub
Feb 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: widget on tx success callback (#5916)
feat: log SWAP_TRANSACTION_COMPLETED for widget transactions
parent
927d35d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
4 deletions
+65
-4
transactions.ts
src/components/Widget/transactions.ts
+65
-4
No files found.
src/components/Widget/transactions.ts
View file @
db6084d7
import
{
sendAnalyticsEvent
,
useTrace
}
from
'
@uniswap/analytics
'
import
{
sendAnalyticsEvent
,
useTrace
}
from
'
@uniswap/analytics
'
import
{
InterfaceEventName
,
InterfaceSectionName
,
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
InterfaceEventName
,
InterfaceSectionName
,
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Currency
,
Percent
}
from
'
@uniswap/sdk-core
'
import
{
import
{
OnTxSuccess
,
TradeType
,
TradeType
,
Transaction
,
Transaction
,
TransactionEventHandlers
,
TransactionEventHandlers
,
TransactionInfo
,
TransactionInfo
,
TransactionType
,
TransactionType
as
WidgetTransactionType
,
TransactionType
as
WidgetTransactionType
,
}
from
'
@uniswap/widgets
'
}
from
'
@uniswap/widgets
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
WrapType
}
from
'
hooks/useWrapCallback
'
import
{
import
{
formatSwapSignedAnalyticsEventProperties
,
formatToDecimal
,
getTokenAddress
}
from
'
lib/utils/analytics
'
formatPercentInBasisPointsNumber
,
formatSwapSignedAnalyticsEventProperties
,
formatToDecimal
,
getTokenAddress
,
}
from
'
lib/utils/analytics
'
import
{
useCallback
,
useMemo
}
from
'
react
'
import
{
useCallback
,
useMemo
}
from
'
react
'
import
{
useTransactionAdder
}
from
'
state/transactions/hooks
'
import
{
useTransactionAdder
}
from
'
state/transactions/hooks
'
import
{
import
{
...
@@ -19,6 +27,42 @@ import {
...
@@ -19,6 +27,42 @@ import {
WrapTransactionInfo
,
WrapTransactionInfo
,
}
from
'
state/transactions/types
'
}
from
'
state/transactions/types
'
import
{
currencyId
}
from
'
utils/currencyId
'
import
{
currencyId
}
from
'
utils/currencyId
'
import
{
computeRealizedPriceImpact
}
from
'
utils/prices
'
interface
AnalyticsEventProps
{
trade
:
Trade
<
Currency
,
Currency
,
TradeType
>
gasUsed
:
string
|
undefined
blockNumber
:
number
|
undefined
hash
:
string
|
undefined
allowedSlippage
:
Percent
succeeded
:
boolean
}
const
formatAnalyticsEventProperties
=
({
trade
,
hash
,
allowedSlippage
,
succeeded
,
gasUsed
,
blockNumber
,
}:
AnalyticsEventProps
)
=>
({
estimated_network_fee_usd
:
gasUsed
,
transaction_hash
:
hash
,
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
:
blockNumber
,
succeeded
,
})
/** Integrates the Widget's transactions, showing the widget's transactions in the app. */
/** Integrates the Widget's transactions, showing the widget's transactions in the app. */
export
function
useSyncWidgetTransactions
()
{
export
function
useSyncWidgetTransactions
()
{
...
@@ -46,7 +90,7 @@ export function useSyncWidgetTransactions() {
...
@@ -46,7 +90,7 @@ export function useSyncWidgetTransactions() {
amount
:
transactionAmount
amount
:
transactionAmount
?
formatToDecimal
(
transactionAmount
,
transactionAmount
?.
currency
.
decimals
)
?
formatToDecimal
(
transactionAmount
,
transactionAmount
?.
currency
.
decimals
)
:
undefined
,
:
undefined
,
type
:
type
===
WidgetTransactionType
.
WRAP
?
WrapType
.
WRAP
:
Wrap
Type
.
UNWRAP
,
type
:
type
===
WidgetTransactionType
.
WRAP
?
TransactionType
.
WRAP
:
Transaction
Type
.
UNWRAP
,
...
trace
,
...
trace
,
}
}
sendAnalyticsEvent
(
InterfaceEventName
.
WRAP_TOKEN_TXN_SUBMITTED
,
eventProperties
)
sendAnalyticsEvent
(
InterfaceEventName
.
WRAP_TOKEN_TXN_SUBMITTED
,
eventProperties
)
...
@@ -94,7 +138,24 @@ export function useSyncWidgetTransactions() {
...
@@ -94,7 +138,24 @@ export function useSyncWidgetTransactions() {
[
addTransaction
,
chainId
,
trace
]
[
addTransaction
,
chainId
,
trace
]
)
)
const
txHandlers
:
TransactionEventHandlers
=
useMemo
(()
=>
({
onTxSubmit
}),
[
onTxSubmit
])
const
onTxSuccess
:
OnTxSuccess
=
useCallback
((
hash
:
string
,
tx
)
=>
{
if
(
tx
.
info
.
type
===
TransactionType
.
SWAP
)
{
const
{
trade
,
slippageTolerance
}
=
tx
.
info
sendAnalyticsEvent
(
SwapEventName
.
SWAP_TRANSACTION_COMPLETED
,
formatAnalyticsEventProperties
({
trade
,
hash
,
gasUsed
:
tx
.
receipt
?.
gasUsed
?.
toString
(),
blockNumber
:
tx
.
receipt
?.
blockNumber
,
allowedSlippage
:
slippageTolerance
,
succeeded
:
tx
.
receipt
?.
status
===
1
,
})
)
}
},
[])
const
txHandlers
:
TransactionEventHandlers
=
useMemo
(()
=>
({
onTxSubmit
,
onTxSuccess
}),
[
onTxSubmit
,
onTxSuccess
])
return
{
transactions
:
{
...
txHandlers
}
}
return
{
transactions
:
{
...
txHandlers
}
}
}
}
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