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

fix speed up/cancel transaction #1413

Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7898e28
socketscan explorer on bridge txs
greg-schrammel Mar 21, 2024
6b32e94
failed txs are expected to not have changes
greg-schrammel Mar 21, 2024
99b864e
fix pending txs data
greg-schrammel Mar 21, 2024
dac519e
fix data display & crashes
greg-schrammel Mar 21, 2024
834c563
Merge branch 'master' into pending-tx-fixes
greg-schrammel Mar 22, 2024
05a56b8
parseTransaction not a promise
greg-schrammel Mar 26, 2024
43ba20e
a
greg-schrammel Mar 26, 2024
a2dc063
Merge branch 'master' into pending-tx-fixes
greg-schrammel Mar 27, 2024
457f15d
formatFee
greg-schrammel Apr 2, 2024
3ef0145
formatValue
greg-schrammel Apr 2, 2024
1bb36cf
formatValue
greg-schrammel Apr 2, 2024
51e3e59
Merge branch 'master' into pending-tx-fixes
greg-schrammel Apr 2, 2024
dd8b1e4
save
greg-schrammel Mar 19, 2024
d36e36b
CustomGasSheet UI fixes
greg-schrammel Mar 20, 2024
479599c
k
greg-schrammel Mar 20, 2024
025bea5
a
greg-schrammel Mar 21, 2024
61aa208
wip
greg-schrammel Mar 21, 2024
6d08ffd
aaaaaaa
greg-schrammel Mar 25, 2024
4668e70
cleanup
greg-schrammel Mar 27, 2024
b72110e
a
greg-schrammel Mar 27, 2024
66595e2
a
greg-schrammel Mar 27, 2024
d40aa48
???????????
greg-schrammel Mar 28, 2024
7388695
ok atleast we fix the prompt state
greg-schrammel Mar 28, 2024
72d4f13
fix error msg
greg-schrammel Mar 28, 2024
5aeaf6e
:)
greg-schrammel Apr 1, 2024
fb3de63
bruh
greg-schrammel Apr 2, 2024
321147f
aaa
greg-schrammel Apr 4, 2024
6785c83
fix: empty activity (#1452)
estebanmino Apr 2, 2024
d7fb787
fix: connection banner visible when on lock screen (#1424)
estebanmino Apr 2, 2024
8b00ee2
changelog: v1.4.25, v1.4.34, v1.4.41 (#1446)
DanielSinclair Apr 2, 2024
c44de03
fix: deprecate isRainbowCurated for swap assets (#1453)
estebanmino Apr 2, 2024
1fcee64
Version Bump (Internal) - v1.4.46
brunobar79 Apr 3, 2024
85aadcc
fix: dont use custom_rpc param (#1444)
estebanmino Apr 3, 2024
2bc997a
fix: upgrade swap sdk for Blast and Zora support (#1448)
DanielSinclair Apr 3, 2024
dbb442e
Version Bump (Internal) - v1.4.47
brunobar79 Apr 4, 2024
39a8577
chore: subtracting token balance if token is hidden (#1455)
magiziz Apr 4, 2024
b1b0acc
fix: BX-1380 (#1458)
estebanmino Apr 4, 2024
dfeea37
fix: BX-1379 (#1457)
estebanmino Apr 4, 2024
2685797
fix ci - bump vitest resolution (#1460)
BrodyHughes Apr 4, 2024
66e26fb
:)
greg-schrammel Apr 4, 2024
6c3bb39
fix gas wei parsings
greg-schrammel Apr 9, 2024
04a7cb0
deserialize BigNumbers
greg-schrammel Apr 9, 2024
9c2c3aa
fix build cancel/speedup tx
greg-schrammel Apr 9, 2024
88915a2
remove log
greg-schrammel Apr 10, 2024
4882311
Merge remote-tracking branch origin/master into gregs/bx-1327-speed-u…
greg-schrammel Apr 10, 2024
3adb7da
Merge remote-tracking branch origin/master into gregs/bx-1327-speed-u…
greg-schrammel Apr 22, 2024
ba4a429
remove console.log
greg-schrammel Apr 22, 2024
cf00899
Merge branch 'master' into gregs/bx-1327-speed-up-tx-rejected-by-rpc-…
greg-schrammel Apr 29, 2024
3d5fe56
i18n
greg-schrammel Apr 29, 2024
6c4b248
deserializeBigNumbers util
greg-schrammel Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/types/transactions.ts
Expand Up @@ -45,6 +45,8 @@ type BaseTransaction = {
};

type: TransactionType;
typeOverride?: 'speed_up' | 'cancel'; // we keep the tx metadata like type "swap" and add this override to indicate it's a speed up or cancel

protocol?: ProtocolType;
title: string;
description?: string;
Expand Down
5 changes: 3 additions & 2 deletions src/core/utils/ethereum.ts
Expand Up @@ -2,6 +2,7 @@ import { isAddress } from '@ethersproject/address';
import { Mnemonic, isValidMnemonic } from '@ethersproject/hdnode';
import { TransactionResponse } from '@ethersproject/providers';
import { parseEther } from '@ethersproject/units';
import BigNumber from 'bignumber.js';
import omit from 'lodash/omit';
import { Address } from 'wagmi';

Expand All @@ -10,7 +11,7 @@ import { ethUnits } from '../references';
import { EthereumWalletType } from '../types/walletTypes';

import { addHexPrefix, isHexStringIgnorePrefix } from './hex';
import { divide, multiply } from './numbers';
import { divide } from './numbers';

export type EthereumWalletSeed = PrivateKey | Mnemonic['phrase'];

Expand Down Expand Up @@ -75,7 +76,7 @@ export const hasPreviousTransactions = async (
};

export const gweiToWei = (gweiAmount: string) => {
const weiAmount = multiply(gweiAmount, ethUnits.gwei);
const weiAmount = new BigNumber(gweiAmount).times(ethUnits.gwei).toFixed(0); // fixed to 0 because wei is the smallest unit
return weiAmount;
};

Expand Down
10 changes: 6 additions & 4 deletions src/core/utils/gas.ts
Expand Up @@ -33,6 +33,7 @@ import {
} from '../types/gas';

import { gweiToWei, weiToGwei } from './ethereum';
import { formatNumber } from './formatNumber';
import { addHexPrefix, convertStringToHex, toHex } from './hex';
import { fetchJsonLocally } from './localJson';
import {
Expand Down Expand Up @@ -107,11 +108,12 @@ export const parseGasDataConfirmationTime = ({
};

export const parseGasFeeParam = ({ wei }: { wei: string }): GasFeeParam => {
const gwei = wei ? weiToGwei(wei) : '';
const _wei = new BigNumber(wei).toFixed(0); // wei is the smallest unit, shouldn't have decimals
const gwei = _wei ? weiToGwei(_wei) : '';
return {
amount: wei,
display: `${gwei} Gwei`,
gwei: `${Math.round(Number(gwei) * 10) / 10}`,
amount: _wei,
display: `${formatNumber(gwei)} Gwei`,
gwei,
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/transactions.ts
Expand Up @@ -328,7 +328,7 @@ export const parseNewTransaction = (
...tx,
status: 'pending',
data: tx.data,
title: i18n.t(`transactions.${tx.type}.${tx.status}`),
title: i18n.t(`transactions.${tx.typeOverride || tx.type}.${tx.status}`),
description: asset?.name || methodName,
from: tx.from,
changes,
Expand Down
Expand Up @@ -211,7 +211,6 @@ export const ExplainerSheet = ({
height="44px"
variant={actionButton?.variant || 'raised'}
onClick={actionButton?.action}
symbol={actionButton?.symbol}
testId="explainer-action-button"
>
<Inline alignVertical="center" space="4px">
Expand Down
2 changes: 1 addition & 1 deletion src/entries/popup/components/SideChainExplainer.tsx
Expand Up @@ -28,7 +28,7 @@ export const getSideChainExplainerParams = (
[ChainId.bsc]: 'bsc',
[ChainId.avalanche]: 'avalanche',
[ChainId.blast]: 'blast',
[ChainId.degen]: 'degen'
[ChainId.degen]: 'degen',
// add new chains here with unique i18n explainer keys
};

Expand Down
25 changes: 23 additions & 2 deletions src/entries/popup/handlers/wallet.ts
Expand Up @@ -2,6 +2,7 @@ import {
TransactionRequest,
TransactionResponse,
} from '@ethersproject/abstract-provider';
import { BigNumber } from '@ethersproject/bignumber';
import { Bytes } from '@ethersproject/bytes';
import { HDNode, Mnemonic } from '@ethersproject/hdnode';
import { keccak256 } from '@ethersproject/keccak256';
Expand Down Expand Up @@ -157,13 +158,33 @@ export const sendTransaction = async (
throw new Error('Unsupported hardware wallet');
}
} else {
return walletAction(
const transactionResponse = await walletAction<TransactionResponse>(
'send_transaction',
params,
) as unknown as TransactionResponse;
);

return deserializeBigNumbers(transactionResponse);
}
};

function deserializeBigNumbers<T>(obj: T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not 100% sure about this solution, open to suggestions
but walletAction bridges to the background worker and back, in this back and forth it serializes BigNumbers as { type: 'BigNumber', _hex: "0x..." }
so sometimes we got an [object Object] instead of the bignumber in some places

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes i've seen this, maybe let's just use hex strings? only sending hex from popup to background and only sending hex from background to popup so we don't have to do this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to do it and got afraid of changing the type and breaking in unexpected places, because it's being casted as TransactionResponse and that is why we didn't caught it for so long to begin with
to do it without changing the type, I'd have to then deserialize by hand like

return {
 ...response,
 maxBaseFee: BigNumber.from(response.maxBaseFee)
 ...
}

which is more error prone and effort

another idea is to do this generic BigNumber deserialization inside walletAction so we don't have to ever think about it again in other places

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okok sounds good, can we move this to a util file somewhere else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

for (const key in obj) {
const v = obj[key];
if (
v &&
typeof v === 'object' &&
'_hex' in v &&
'type' in v &&
v.type === 'BigNumber'
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
obj[key] = BigNumber.from(obj[key]._hex);
}
}
return obj;
}

export async function executeRap<T extends RapTypes>({
rapActionParameters,
type,
Expand Down
2 changes: 1 addition & 1 deletion src/entries/popup/hooks/useCurrentHomeSheet.tsx
Expand Up @@ -26,7 +26,7 @@ export function useCurrentHomeSheet() {
switch (sheet) {
case 'cancel':
case 'speedUp':
return selectedTransaction ? (
return selectedTransaction?.status === 'pending' ? (
<SpeedUpAndCancelSheet
currentSheet={sheet}
onClose={closeSheet}
Expand Down
54 changes: 44 additions & 10 deletions src/entries/popup/pages/home/Activity/ActivityDetails.tsx
Expand Up @@ -9,7 +9,11 @@ import { useApprovals } from '~/core/resources/approvals/approvals';
import { useTransaction } from '~/core/resources/transactions/transaction';
import { useCurrentAddressStore, useCurrentCurrencyStore } from '~/core/state';
import { ChainId, ChainNameDisplay } from '~/core/types/chains';
import { RainbowTransaction, TxHash } from '~/core/types/transactions';
import {
PendingTransaction,
RainbowTransaction,
TxHash,
} from '~/core/types/transactions';
import { truncateAddress } from '~/core/utils/address';
import { findRainbowChainForChainId } from '~/core/utils/chains';
import { copy } from '~/core/utils/copy';
Expand Down Expand Up @@ -46,6 +50,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '~/entries/popup/components/DropdownMenu/DropdownMenu';
import { ExplainerSheet } from '~/entries/popup/components/ExplainerSheet/ExplainerSheet';
import { Navbar } from '~/entries/popup/components/Navbar/Navbar';
import { useRainbowNavigate } from '~/entries/popup/hooks/useRainbowNavigate';
import { useWallets } from '~/entries/popup/hooks/useWallets';
Expand Down Expand Up @@ -288,13 +293,40 @@ function NetworkData({ transaction: tx }: { transaction: RainbowTransaction }) {
);
}

function SpeedUpErrorExplainer() {
const [searchParams, setSearchParams] = useSearchParams();
const explainer = searchParams.get('explainer');

return (
<ExplainerSheet
show={explainer === 'speed_up_error'}
onClickOutside={() => setSearchParams({})}
header={{
icon: <Symbol symbol="xmark.circle.fill" color="red" size={32} />,
}}
title="Failed to speed up transaction"
description={[
'A speed up can fail when the state of the network changed since you first submitted the transaction',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielSinclair let's define a copy for this and I add to the translations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg-schrammel Some copy:

"Speed up failed"

"Attempts to speed up a transaction can fail during network congestion, gas limit increases, or when the original transaction is confirmed first"

]}
actionButton={{
action: () => setSearchParams({ sheet: 'cancel' }),
symbol: 'trash.fill',
symbolSide: 'left',
label: 'Cancel Transaction',
labelColor: 'label',
}}
/>
);
}

const SpeedUpOrCancel = ({
transaction,
}: {
transaction: RainbowTransaction;
transaction: PendingTransaction;
}) => {
const [searchParams] = useSearchParams();
const navigate = useRainbowNavigate();
const [searchParams] = useSearchParams();

const sheetParam = searchParams.get('sheet');
const sheet =
sheetParam === 'speedUp' || sheetParam === 'cancel' ? sheetParam : 'none';
Expand All @@ -303,6 +335,7 @@ const SpeedUpOrCancel = ({
state: { skipTransitionOnRoute: ROUTES.HOME },
});
};

return (
<>
<Box display="flex" flexDirection="column" gap="8px">
Expand All @@ -327,13 +360,12 @@ const SpeedUpOrCancel = ({
{i18n.t('speed_up_and_cancel.cancel')}
</Button>
</Box>
{sheet !== 'none' && (
<SpeedUpAndCancelSheet
currentSheet={sheet}
transaction={transaction}
onClose={() => setSheet('none')}
/>
)}
<SpeedUpAndCancelSheet
currentSheet={sheet}
transaction={transaction}
onClose={() => setSheet('none')}
/>
<SpeedUpErrorExplainer />
</>
);
};
Expand Down Expand Up @@ -545,6 +577,8 @@ export function ActivityDetails() {
});
const navigate = useRainbowNavigate();

console.log(transaction);
greg-schrammel marked this conversation as resolved.
Show resolved Hide resolved

const { data: approvals } = useApprovals(
{
address: currentAddress,
Expand Down