Skip to content

Commit

Permalink
Merge pull request #1682 from synapsecns/fe/transactions-sdk
Browse files Browse the repository at this point in the history
Fe/transactions sdk
  • Loading branch information
aureliusbtc authored Jan 5, 2024
2 parents d8304c4 + c9f5bcb commit 03468bb
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,19 @@ export const MostRecentTransaction = () => {
return transactions
}, [userHistoricalTransactions, fallbackQueryHistoricalTransactions])

const lastPendingBridgeTransaction: PendingBridgeTransaction = useMemo(() => {
return pendingBridgeTransactions?.[0]
}, [pendingBridgeTransactions])
const lastPendingBridgeTransaction: PendingBridgeTransaction =
pendingBridgeTransactions?.[0]

const lastPendingTransaction: BridgeTransaction = useMemo(() => {
return pendingAwaitingCompletionTransactionsWithFallback?.[0]
}, [pendingAwaitingCompletionTransactionsWithFallback])
const lastPendingTransaction: BridgeTransaction =
pendingAwaitingCompletionTransactionsWithFallback?.[0]

const lastHistoricalTransaction: BridgeTransaction = useMemo(() => {
return userHistoricalTransactionsWithFallback?.[0]
}, [userHistoricalTransactionsWithFallback])
const lastHistoricalTransaction: BridgeTransaction =
userHistoricalTransactionsWithFallback?.[0]

const recentMinutesInUnix: number = 15 * 60

const isLastHistoricalTransactionRecent: boolean = useMemo(
() =>
currentTime - lastHistoricalTransaction?.toInfo?.time <
recentMinutesInUnix,
[currentTime]
)
const isLastHistoricalTransactionRecent: boolean =
currentTime - lastHistoricalTransaction?.toInfo?.time < recentMinutesInUnix

const seenLastHistoricalTransaction: boolean = useMemo(() => {
if (!seenHistoricalTransactions || !userHistoricalTransactions) {
Expand All @@ -133,136 +126,114 @@ export const MostRecentTransaction = () => {

let transaction

return useMemo(() => {
if (
isUserHistoricalTransactionsLoading ||
isUserPendingTransactionsLoading
) {
return null
}

if (!masqueradeActive && lastPendingBridgeTransaction) {
transaction = lastPendingBridgeTransaction as PendingBridgeTransaction
return (
<div
data-test-id="most-recent-transaction-bridge-pending"
className="mt-6"
>
<PendingTransaction
connectedAddress={address as Address}
originChain={transaction.originChain as Chain}
originToken={transaction.originToken as Token}
originValue={Number(transaction.originValue)}
destinationChain={transaction.destinationChain as Chain}
destinationToken={transaction.destinationToken as Token}
estimatedDuration={transaction?.estimatedTime}
bridgeModuleName={transaction?.bridgeModuleName}
startedTimestamp={
transaction.timestamp ? transaction.timestamp : transaction.id
}
transactionHash={transaction.transactionHash}
isSubmitted={transaction.isSubmitted}
transactionType={TransactionType.PENDING}
/>
</div>
)
}

if (!masqueradeActive && lastPendingTransaction) {
transaction = lastPendingTransaction as BridgeTransaction
return (
<div data-test-id="most-recent-transaction-pending" className="mt-6">
<PendingTransaction
connectedAddress={address as Address}
startedTimestamp={transaction?.fromInfo?.time}
transactionHash={transaction?.fromInfo?.txnHash}
transactionType={TransactionType.PENDING}
originValue={transaction?.fromInfo?.value}
originChain={CHAINS_BY_ID[transaction?.fromInfo?.chainID] as Chain}
destinationChain={
CHAINS_BY_ID[transaction?.fromInfo?.destinationChainID] as Chain
}
originToken={
tokenAddressToToken(
transaction?.fromInfo?.chainID,
transaction?.fromInfo?.tokenAddress
) as Token
}
destinationToken={
tokenAddressToToken(
transaction?.toInfo?.chainID,
transaction?.toInfo?.tokenAddress
) as Token
}
formattedEventType={transaction?.fromInfo?.formattedEventType}
estimatedDuration={transaction?.estimatedTime}
destinationAddress={transaction?.fromInfo?.address as Address}
isSubmitted={transaction?.fromInfo?.txnHash ? true : false}
isCompleted={transaction?.toInfo?.time ? true : false}
kappa={transaction?.kappa}
/>
</div>
)
}

if (
!masqueradeActive &&
lastHistoricalTransaction &&
isLastHistoricalTransactionRecent &&
!seenLastHistoricalTransaction
) {
transaction = lastHistoricalTransaction as BridgeTransaction
return (
<div data-test-id="most-recent-transaction-historical" className="mt-6">
<PendingTransaction
connectedAddress={address as Address}
destinationAddress={transaction?.fromInfo?.address as Address}
startedTimestamp={transaction?.fromInfo?.time}
completedTimestamp={transaction?.toInfo?.time}
transactionHash={transaction?.fromInfo?.txnHash}
kappa={transaction?.kappa}
transactionType={TransactionType.PENDING}
originValue={transaction?.fromInfo?.value}
destinationValue={transaction?.toInfo?.value}
originChain={CHAINS_BY_ID[transaction?.fromInfo?.chainID] as Chain}
destinationChain={
CHAINS_BY_ID[transaction?.fromInfo?.destinationChainID] as Chain
}
originToken={
tokenAddressToToken(
transaction?.fromInfo?.chainID,
transaction?.fromInfo?.tokenAddress
) as Token
}
destinationToken={
tokenAddressToToken(
transaction?.toInfo?.chainID,
transaction?.toInfo?.tokenAddress
) as Token
}
formattedEventType={transaction?.fromInfo?.formattedEventType}
isSubmitted={transaction?.fromInfo?.txnHash ? true : false}
isCompleted={true}
/>
</div>
)
}
}, [
currentTime,
lastPendingBridgeTransaction,
lastHistoricalTransaction,
lastPendingTransaction,
userHistoricalTransactions,
isUserHistoricalTransactionsLoading,
isUserPendingTransactionsLoading,
seenHistoricalTransactions,
pendingAwaitingCompletionTransactions,
fallbackQueryHistoricalTransactions,
fallbackQueryPendingTransactions,
pendingBridgeTransactions,
masqueradeActive,
seenLastHistoricalTransaction,
isUserHistoricalTransactionsLoading,
isUserPendingTransactionsLoading,
])
if (isUserHistoricalTransactionsLoading || isUserPendingTransactionsLoading) {
return null
}

if (!masqueradeActive && lastPendingBridgeTransaction) {
transaction = lastPendingBridgeTransaction as PendingBridgeTransaction
return (
<div
data-test-id="most-recent-transaction-bridge-pending"
className="mt-6"
>
<PendingTransaction
connectedAddress={address as Address}
originChain={transaction.originChain as Chain}
originToken={transaction.originToken as Token}
originValue={Number(transaction.originValue)}
destinationChain={transaction.destinationChain as Chain}
destinationToken={transaction.destinationToken as Token}
estimatedDuration={transaction?.estimatedTime}
bridgeModuleName={transaction?.bridgeModuleName}
startedTimestamp={
transaction.timestamp ? transaction.timestamp : transaction.id
}
transactionHash={transaction.transactionHash}
isSubmitted={transaction.isSubmitted}
transactionType={TransactionType.PENDING}
/>
</div>
)
}

if (!masqueradeActive && lastPendingTransaction) {
transaction = lastPendingTransaction as BridgeTransaction
return (
<div data-test-id="most-recent-transaction-pending" className="mt-6">
<PendingTransaction
connectedAddress={address as Address}
startedTimestamp={transaction?.fromInfo?.time}
transactionHash={transaction?.fromInfo?.txnHash}
transactionType={TransactionType.PENDING}
originValue={transaction?.fromInfo?.value}
originChain={CHAINS_BY_ID[transaction?.fromInfo?.chainID] as Chain}
destinationChain={
CHAINS_BY_ID[transaction?.fromInfo?.destinationChainID] as Chain
}
originToken={
tokenAddressToToken(
transaction?.fromInfo?.chainID,
transaction?.fromInfo?.tokenAddress
) as Token
}
destinationToken={
tokenAddressToToken(
transaction?.toInfo?.chainID,
transaction?.toInfo?.tokenAddress
) as Token
}
formattedEventType={transaction?.fromInfo?.formattedEventType}
estimatedDuration={transaction?.estimatedTime}
destinationAddress={transaction?.fromInfo?.address as Address}
isSubmitted={transaction?.fromInfo?.txnHash ? true : false}
isCompleted={transaction?.toInfo?.time ? true : false}
kappa={transaction?.kappa}
/>
</div>
)
}

if (
!masqueradeActive &&
lastHistoricalTransaction &&
isLastHistoricalTransactionRecent &&
!seenLastHistoricalTransaction
) {
transaction = lastHistoricalTransaction as BridgeTransaction
return (
<div data-test-id="most-recent-transaction-historical" className="mt-6">
<PendingTransaction
connectedAddress={address as Address}
destinationAddress={transaction?.fromInfo?.address as Address}
startedTimestamp={transaction?.fromInfo?.time}
completedTimestamp={transaction?.toInfo?.time}
transactionHash={transaction?.fromInfo?.txnHash}
kappa={transaction?.kappa}
transactionType={TransactionType.PENDING}
originValue={transaction?.fromInfo?.value}
destinationValue={transaction?.toInfo?.value}
originChain={CHAINS_BY_ID[transaction?.fromInfo?.chainID] as Chain}
destinationChain={
CHAINS_BY_ID[transaction?.fromInfo?.destinationChainID] as Chain
}
originToken={
tokenAddressToToken(
transaction?.fromInfo?.chainID,
transaction?.fromInfo?.tokenAddress
) as Token
}
destinationToken={
tokenAddressToToken(
transaction?.toInfo?.chainID,
transaction?.toInfo?.tokenAddress
) as Token
}
formattedEventType={transaction?.fromInfo?.formattedEventType}
isSubmitted={transaction?.fromInfo?.txnHash ? true : false}
isCompleted={true}
/>
</div>
)
}
}
Loading

0 comments on commit 03468bb

Please sign in to comment.