Skip to content

Commit

Permalink
aaaaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel committed Mar 18, 2024
1 parent 8e7bf65 commit 60e651c
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 81 deletions.
1 change: 1 addition & 0 deletions src/core/providers/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChainId } from '../types/chains';

export const proxyRpcEndpoint = (endpoint: string, chainId: ChainId) => {
if (
endpoint &&
endpoint !== 'http://127.0.0.1:8545' &&
endpoint !== 'http://localhost:8545' &&
!endpoint.includes('http://10.') &&
Expand Down
7 changes: 1 addition & 6 deletions src/core/resources/transactions/consolidatedTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function parseConsolidatedTransactions(
currency: SupportedCurrencyKey,
) {
const data = message?.payload?.transactions || [];
const parsedTransactionPromises = data
return data
.map((tx) =>
parseTransaction({
tx,
Expand All @@ -145,11 +145,6 @@ async function parseConsolidatedTransactions(
}),
)
.filter(Boolean);

const parsedConsolidatedTransactions = (
await Promise.all(parsedTransactionPromises)
).flat();
return parsedConsolidatedTransactions;
}

// ///////////////////////////////////////////////
Expand Down
62 changes: 59 additions & 3 deletions src/core/resources/transactions/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatUnits } from '@ethersproject/units';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { Hash, getProvider } from '@wagmi/core';
import { Address } from 'wagmi';
Expand All @@ -10,7 +11,11 @@ import {
consolidatedTransactionsQueryFunction,
consolidatedTransactionsQueryKey,
} from '~/core/resources/transactions/consolidatedTransactions';
import { useCurrentAddressStore, useCurrentCurrencyStore } from '~/core/state';
import {
pendingTransactionsStore,
useCurrentAddressStore,
useCurrentCurrencyStore,
} from '~/core/state';
import { useTestnetModeStore } from '~/core/state/currentSettings/testnetMode';
import { ChainId } from '~/core/types/chains';
import {
Expand Down Expand Up @@ -48,6 +53,12 @@ export const fetchTransaction = async ({
});
const tx = response.data.payload.transaction;
if (response.data.meta.status === 'pending') {
const { pendingTransactions } = pendingTransactionsStore.getState();
const localPendingTx = pendingTransactions[address]?.find(
(tx) => tx.hash === hash,
);
if (localPendingTx) return localPendingTx;

const providerTx = await getCustomChainTransaction({ chainId, hash });
return providerTx;
}
Expand All @@ -58,6 +69,7 @@ export const fetchTransaction = async ({
logger.error(new RainbowError('fetchTransaction: '), {
message: (e as Error)?.message,
});
throw e; // log & rethrow
}
};

Expand Down Expand Up @@ -133,6 +145,11 @@ const getCustomChainTransaction = async ({
? await provider.getBlock(transaction?.blockHash)
: undefined;

// backend returns the value formatted to decimals, so lets do the same here
const decimals = 18; // assuming every chain uses 18 decimals
console.log('aaaaaaa', transaction);
const value = formatUnits(transaction.value, decimals);

const parsedTransaction = transaction.blockNumber
? ({
status: 'confirmed',
Expand All @@ -146,7 +163,7 @@ const getCustomChainTransaction = async ({
from: transaction.from as Address,
to: transaction.to as Address,
data: transaction.data,
value: transaction.value.toString(),
value: value,
type: 'send',
title: i18n.t('transactions.send.confirmed'),
baseFee: block?.baseFeePerGas?.toString(),
Expand All @@ -162,7 +179,7 @@ const getCustomChainTransaction = async ({
from: transaction.from as Address,
to: transaction.to as Address,
data: transaction.data,
value: transaction.value.toString(),
value: value,
type: 'send',
title: i18n.t('transactions.send.pending'),
} satisfies PendingTransaction);
Expand Down Expand Up @@ -222,3 +239,42 @@ export const useTransaction = ({
: backendTransactionIsFetched,
};
};

// {
// "hash": "0xa4b337726133df28af806ab316cf7faeb7a1bbfa39d931cd218a25f0ea6781ba",
// "type": 2,
// "accessList": [],
// "blockHash": null,
// "blockNumber": null,
// "transactionIndex": null,
// "confirmations": 0,
// "from": "0x507F0daA42b215273B8a063B092ff3b6d27767aF",
// "gasPrice": {
// "type": "BigNumber",
// "hex": "0x04e3b29200"
// },
// "maxPriorityFeePerGas": {
// "type": "BigNumber",
// "hex": "0x3b9aca00"
// },
// "maxFeePerGas": {
// "type": "BigNumber",
// "hex": "0x04e3b29200"
// },
// "gasLimit": {
// "type": "BigNumber",
// "hex": "0x0298ba"
// },
// "to": "0x00000000009726632680FB29d3F7A9734E3010E2",
// "value": {
// "type": "BigNumber",
// "hex": "0x18de76816d8000"
// },
// "nonce": 230,
// "data": "0x3c2b9a7d0000000000000000000000007fd4d7737597e7b4ee22acbf8d94362343ae0a790000000000000000000000001111111254eeb25477b68fb85ed929f73a96058200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000361d6c5d380000000000000000000000000000000000000000000000000000000000000000c80502b1c500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018a8591510480000000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000180000000000000003b6d0340aaea0db2b27344f20e0245d3b058d746e9dd98d5520b7e0f000000000000000000000000000000000000000000000000e76c9849",
// "r": "0xec9fb10f291fde2dda7795b9a028fe5d7d752baf66e175038a9e22db3d2567e4",
// "s": "0x70c9c53275f1348bd67d4c43187675d78e05be0061e2f8a9b882aa7de7703b6c",
// "v": 0,
// "creates": null,
// "chainId": 1
// }
6 changes: 4 additions & 2 deletions src/core/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ export function parseTransaction({

if (
!type ||
(transactionTypeShouldHaveChanges(type) && changes.length === 0) ||
!tx.address_from
!tx.address_from ||
(status !== 'failed' && // failed txs won't have changes
transactionTypeShouldHaveChanges(type) &&
changes.length === 0)
)
return; // filters some spam or weird api responses

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { AnimatePresence, motion } from 'framer-motion';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
Expand Down Expand Up @@ -273,6 +267,7 @@ export const CustomGasSheet = ({
setMaxBaseFee(prevSelectedGas?.maxBaseFee?.gwei);
}
setSelectedSpeedOption(GasSpeed.CUSTOM);
console.log('updateCustomMaxPriorityFee', maxPriorityFee);
setCustomMaxPriorityFee(maxPriorityFee);
setMaxPriorityFee(maxPriorityFee);
const normalSpeed = gasFeeParamsBySpeed?.normal as GasFeeParams;
Expand Down
48 changes: 48 additions & 0 deletions src/entries/popup/hooks/useGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,56 @@ const useGas = ({

const setCustomMaxPriorityFee = useCallback((maxPriorityFee = '0') => {
setInternalMaxPriorityFee(maxPriorityFee);
// if (!nativeAsset) return;

// console.log('setCustomMaxPriorityFee', maxPriorityFee);

// const { data } = gasData as MeteorologyResponse;
// const currentBaseFee = data.currentBaseFee;
// const secondsPerNewBlock = data.secondsPerNewBlock;

// const blocksToConfirmation = {
// byBaseFee: data.blocksToConfirmationByBaseFee,
// byPriorityFee: data.blocksToConfirmationByPriorityFee,
// };

// const maxBaseFee = (storeGasFeeParamsBySpeed?.custom as GasFeeParams)
// ?.maxBaseFee?.amount;

// let maxPriorityFeeWei = gweiToWei(maxPriorityFee || '0');
// // Set the flashbots minimum
// if (flashbotsEnabled && Number(maxPriorityFee) < FLASHBOTS_MIN_TIP) {
// maxPriorityFeeWei = gweiToWei(FLASHBOTS_MIN_TIP.toString());
// }

// const newCustomSpeed = parseCustomGasFeeParams({
// currentBaseFee,
// maxPriorityFeeWei,
// speed: GasSpeed.CUSTOM,
// baseFeeWei: maxBaseFee,
// blocksToConfirmation,
// gasLimit: estimatedGasLimit || `${gasUnits.basic_transfer}`,
// nativeAsset,
// currency: currentCurrency,
// secondsPerNewBlock,
// });
// setCustomSpeed(newCustomSpeed);
// },
// [
// currentCurrency,
// estimatedGasLimit,
// flashbotsEnabled,
// gasData,
// nativeAsset,
// setCustomSpeed,
// storeGasFeeParamsBySpeed?.custom,
// ],
}, []);

useEffect(() => {
if (
!gasData ||
!debouncedMaxBaseFee ||
prevDebouncedMaxBaseFee === debouncedMaxBaseFee ||
!enabled ||
chainId !== ChainId.mainnet ||
Expand Down Expand Up @@ -146,6 +191,7 @@ const useGas = ({
useEffect(() => {
if (
!gasData ||
!debouncedMaxPriorityFee ||
prevDebouncedMaxPriorityFee === debouncedMaxPriorityFee ||
!enabled ||
chainId !== ChainId.mainnet ||
Expand All @@ -164,6 +210,8 @@ const useGas = ({
const maxBaseFee = (storeGasFeeParamsBySpeed?.custom as GasFeeParams)
?.maxBaseFee?.amount;

console.log('setCustomMaxPriorityFee', debouncedMaxPriorityFee);

let maxPriorityFeeWei = gweiToWei(debouncedMaxPriorityFee || '0');
// Set the flashbots minimum
if (
Expand Down
33 changes: 15 additions & 18 deletions src/entries/popup/pages/home/Activity/ActivityContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
import { ReactNode, useCallback, useRef, useState } from 'react';

import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
import { useCurrentHomeSheetStore } from '~/core/state/currentHomeSheet';
import { useSelectedTransactionStore } from '~/core/state/selectedTransaction';
import { ChainId } from '~/core/types/chains';
import { RainbowTransaction } from '~/core/types/transactions';
import { truncateAddress } from '~/core/utils/address';
import { copy } from '~/core/utils/copy';
Expand Down Expand Up @@ -45,10 +44,7 @@ export function ActivityContextMenu({
});
};

const viewOnExplorer = () => {
const explorer = getTransactionBlockExplorer(transaction);
goToNewTab({ url: explorer?.url });
};
const explorer = getTransactionBlockExplorer(transaction);

const onSpeedUp = () => {
setCurrentHomeSheet('speedUp');
Expand Down Expand Up @@ -78,14 +74,15 @@ export function ActivityContextMenu({
},
});

useEffect(() => {
const onOpenChange = (open: boolean) => {
if (!open) {
setSelectedTransaction(undefined);
}
}, [open, setSelectedTransaction]);
setOpen(open);
};

return (
<ContextMenu onOpenChange={setOpen}>
<ContextMenu onOpenChange={onOpenChange}>
<ContextMenuTrigger onTrigger={onTrigger}>{children}</ContextMenuTrigger>
<ContextMenuContent>
{transaction?.status === 'pending' && (
Expand All @@ -112,15 +109,15 @@ export function ActivityContextMenu({
</>
)}

<ContextMenuItem
symbolLeft="binoculars.fill"
onSelect={viewOnExplorer}
shortcut={shortcuts.activity.VIEW_TRANSACTION.display}
>
{transaction?.chainId === ChainId.mainnet
? i18n.t('speed_up_and_cancel.view_on_etherscan')
: i18n.t('speed_up_and_cancel.view_on_explorer')}
</ContextMenuItem>
{explorer && (
<ContextMenuItem
symbolLeft="binoculars.fill"
onSelect={() => goToNewTab({ url: explorer.url })}
shortcut={shortcuts.activity.VIEW_TRANSACTION.display}
>
{i18n.t('view_on_explorer', { explorer: explorer.name })}
</ContextMenuItem>
)}

<ContextMenuItem
symbolLeft="doc.on.doc.fill"
Expand Down

0 comments on commit 60e651c

Please sign in to comment.