diff --git a/src/background/transactions/TransactionService.ts b/src/background/transactions/TransactionService.ts index e43a4db28..e1c083ccd 100644 --- a/src/background/transactions/TransactionService.ts +++ b/src/background/transactions/TransactionService.ts @@ -89,6 +89,7 @@ export class TransactionService { } constructor() { + console.log('hello TS') this.transactionsStore = new TransactionsStore([], 'transactions'); this.transactionsPoller = new TransactionsPoller(); TransactionService.emitter.on('alarm', () => { @@ -225,6 +226,10 @@ export class TransactionService { initiator, timestamp: Date.now(), }; + if (addressAction && !isLocalAddressAction(addressAction)) { + newItem.addressAction = addressAction; + console.log('saving addressAction', { addressAction }); + } if ( addressAction && isLocalAddressAction(addressAction) && diff --git a/src/modules/ethereum/transactions/addressAction/addressActionMain.ts b/src/modules/ethereum/transactions/addressAction/addressActionMain.ts index 300252e5c..180daa23e 100644 --- a/src/modules/ethereum/transactions/addressAction/addressActionMain.ts +++ b/src/modules/ethereum/transactions/addressAction/addressActionMain.ts @@ -31,6 +31,20 @@ export function isLocalAddressAction( return 'local' in addressAction && addressAction.local; } +export function toLocalAddressAction( + addressAction: AddressAction, + status: ClientTransactionStatus +): LocalAddressAction { + return { + ...addressAction, + local: true, + transaction: { + ...addressAction.transaction, + status, + }, + }; +} + export const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'; diff --git a/src/modules/ethereum/transactions/addressAction/creators.ts b/src/modules/ethereum/transactions/addressAction/creators.ts index fa81405da..3406bc1e9 100644 --- a/src/modules/ethereum/transactions/addressAction/creators.ts +++ b/src/modules/ethereum/transactions/addressAction/creators.ts @@ -22,7 +22,11 @@ import { type TransactionAction, } from '../describeTransaction'; import type { ChainId } from '../ChainId'; -import { ZERO_HASH, type LocalAddressAction } from './addressActionMain'; +import { + ZERO_HASH, + toLocalAddressAction, + type LocalAddressAction, +} from './addressActionMain'; export async function createActionContent( action: TransactionAction, @@ -121,7 +125,18 @@ export async function pendingTransactionToAddressAction( currency: string, client: Client ): Promise { - const { transaction, hash, receipt, timestamp, dropped } = transactionObject; + const { transaction, hash, receipt, timestamp, dropped, addressAction } = + transactionObject; + const status = receipt + ? receipt.status === 1 + ? 'confirmed' + : 'failed' + : dropped + ? 'dropped' + : 'pending'; + if (addressAction) { + return toLocalAddressAction(addressAction, status); + } let chain: Chain | null; const chainId = normalizeChainId(transaction.chainId); const networks = await loadNetworkByChainId(chainId); @@ -150,13 +165,7 @@ export async function pendingTransactionToAddressAction( : // It's okay to fallback to a stringified chainId because this is // only a representational object valueToHex(transaction.chainId), - status: receipt - ? receipt.status === 1 - ? 'confirmed' - : 'failed' - : dropped - ? 'dropped' - : 'pending', + status, fee: null, nonce: transaction.nonce || 0, sponsored: false, diff --git a/src/modules/ethereum/transactions/types.ts b/src/modules/ethereum/transactions/types.ts index 9db735318..027bf8ccd 100644 --- a/src/modules/ethereum/transactions/types.ts +++ b/src/modules/ethereum/transactions/types.ts @@ -1,6 +1,8 @@ import type { AddressAction } from 'defi-sdk'; import type { ethers } from 'ethers'; +type AddressActionStoredV1 = AddressAction; + export interface TransactionObject { hash: string; timestamp: number; @@ -9,6 +11,7 @@ export interface TransactionObject { receipt?: ethers.providers.TransactionReceipt; dropped?: boolean; relatedTransactionHash?: string; // hash of related transaction (cancelled or sped-up) + addressAction?: AddressActionStoredV1; } export type StoredTransactions = Array; diff --git a/src/ui/pages/History/ActionItem/ActionItem.tsx b/src/ui/pages/History/ActionItem/ActionItem.tsx index 4c5ceead9..62104e629 100644 --- a/src/ui/pages/History/ActionItem/ActionItem.tsx +++ b/src/ui/pages/History/ActionItem/ActionItem.tsx @@ -22,6 +22,7 @@ import type { import { getActionAddress, getActionAsset, + isLocalAddressAction, } from 'src/modules/ethereum/transactions/addressAction'; import { getFungibleAsset } from 'src/modules/ethereum/transactions/actionAsset'; import { truncateAddress } from 'src/ui/shared/truncateAddress'; @@ -501,7 +502,7 @@ export function ActionItem({ if (!networks || !addressAction) { return null; } - return 'local' in addressAction && addressAction.local ? ( + return isLocalAddressAction(addressAction) ? ( ) : (