Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
everdimension committed Jul 17, 2024
1 parent 821d073 commit 8d4059d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/background/transactions/TransactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
27 changes: 18 additions & 9 deletions src/modules/ethereum/transactions/addressAction/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -117,7 +121,18 @@ export async function pendingTransactionToAddressAction(
loadNetworkByChainId: (chainId: ChainId) => Promise<Networks>,
client: Client
): Promise<LocalAddressAction> {
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);
Expand Down Expand Up @@ -146,13 +161,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,
Expand Down
3 changes: 3 additions & 0 deletions src/modules/ethereum/transactions/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TransactionObject>;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/pages/History/ActionItem/ActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -497,7 +498,7 @@ export function ActionItem({
if (!networks || !addressAction) {
return null;
}
return 'local' in addressAction && addressAction.local ? (
return isLocalAddressAction(addressAction) ? (
<ActionItemLocal action={addressAction} networks={networks} />
) : (
<ActionItemBackend
Expand Down

0 comments on commit 8d4059d

Please sign in to comment.