Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Pending transaction details #575

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -121,7 +125,18 @@ export async function pendingTransactionToAddressAction(
currency: string,
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 @@ -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,
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 @@ -501,7 +502,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
Loading