-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
83 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import { trackEvent, WALLET_EVENTS } from '@/services/analytics' | ||
import { getTxDetails } from '@/services/tx/txDetails' | ||
import { TxEvent, txSubscribe } from '@/services/tx/txEvents' | ||
import { useEffect } from 'react' | ||
import useChainId from './useChainId' | ||
|
||
const events = { | ||
[TxEvent.SIGNED]: WALLET_EVENTS.OFF_CHAIN_SIGNATURE, | ||
[TxEvent.PROCESSING]: WALLET_EVENTS.ON_CHAIN_INTERACTION, | ||
[TxEvent.RELAYING]: WALLET_EVENTS.RELAYED_EXECUTION, | ||
[TxEvent.SIGNED]: WALLET_EVENTS.OFFCHAIN_SIGNATURE, | ||
[TxEvent.PROCESSING]: WALLET_EVENTS.ONCHAIN_INTERACTION, | ||
[TxEvent.PROCESSING_MODULE]: WALLET_EVENTS.ONCHAIN_INTERACTION, | ||
[TxEvent.RELAYING]: WALLET_EVENTS.ONCHAIN_INTERACTION, | ||
} | ||
|
||
export const useTxTracking = (): void => { | ||
const chainId = useChainId() | ||
|
||
useEffect(() => { | ||
const unsubFns = Object.entries(events).map(([txEvent, analyticsEvent]) => | ||
txSubscribe(txEvent as TxEvent, () => { | ||
trackEvent(analyticsEvent) | ||
txSubscribe(txEvent as TxEvent, async (detail) => { | ||
const txId = 'txId' in detail ? detail.txId : undefined | ||
const txHash = 'txHash' in detail ? detail.txHash : undefined | ||
const id = txId || txHash | ||
|
||
let origin = '' | ||
if (id) { | ||
try { | ||
const txDetails = await getTxDetails(chainId, id) | ||
origin = txDetails.safeAppInfo?.url || '' | ||
} catch {} | ||
} | ||
|
||
trackEvent({ | ||
...analyticsEvent, | ||
label: origin, | ||
}) | ||
}), | ||
) | ||
|
||
return () => { | ||
unsubFns.forEach((unsub) => unsub()) | ||
} | ||
}, []) | ||
}, [chainId]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import memoize from 'lodash/memoize' | ||
import { getTransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' | ||
|
||
/** | ||
* Get and memoize transaction details from Safe Gatewa | ||
* @param id Transaction id or hash | ||
* @param chainId Chain id | ||
* @returns Transaction details | ||
*/ | ||
export const getTxDetails = memoize( | ||
(id: string, chainId: string) => { | ||
return getTransactionDetails(id, chainId) | ||
}, | ||
(id: string, chainId: string) => `${id}-${chainId}`, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.