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 all 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
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions src/core/utils/deserializeBigNumbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BigNumber } from '@ethersproject/bignumber';

export function deserializeBigNumbers<T>(obj: T) {
for (const key in obj) {
const v = obj[key];
if (!v || typeof v !== 'object') continue;

if ('hex' in v && 'type' in v && v.type === 'BigNumber') {
(obj[key] as BigNumber) = BigNumber.from(v.hex);
} else {
obj[key] = deserializeBigNumbers(v);
}
}

return obj;
}
5 changes: 3 additions & 2 deletions src/core/utils/ethereum.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
7 changes: 5 additions & 2 deletions src/entries/popup/handlers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '~/core/types/gas';
import { KeychainWallet } from '~/core/types/keychainTypes';
import { ExecuteRapResponse } from '~/core/types/transactions';
import { deserializeBigNumbers } from '~/core/utils/deserializeBigNumbers';
import { hasPreviousTransactions } from '~/core/utils/ethereum';
import { estimateGasWithPadding } from '~/core/utils/gas';
import { toHex } from '~/core/utils/hex';
Expand Down Expand Up @@ -157,10 +158,12 @@ 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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/entries/popup/hooks/useCurrentHomeSheet.tsx
Original file line number Diff line number Diff line change
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
50 changes: 40 additions & 10 deletions src/entries/popup/pages/home/Activity/ActivityDetails.tsx
Original file line number Diff line number Diff line change
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,38 @@ 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={i18n.t('speed_up_and_cancel.speed_up_failed.title')}
description={[i18n.t('speed_up_and_cancel.speed_up_failed.description')]}
actionButton={{
action: () => setSearchParams({ sheet: 'cancel' }),
symbol: 'trash.fill',
symbolSide: 'left',
label: i18n.t('speed_up_and_cancel.cancel_title'),
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 +333,7 @@ const SpeedUpOrCancel = ({
state: { skipTransitionOnRoute: ROUTES.HOME },
});
};

return (
<>
<Box display="flex" flexDirection="column" gap="8px">
Expand All @@ -327,13 +358,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