Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into gregs/bx-1575-show-…
Browse files Browse the repository at this point in the history
…popular-in-rainbow-tokens
  • Loading branch information
greg-schrammel committed Sep 13, 2024
2 parents 32687d4 + f80d999 commit d75df08
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 107 deletions.
6 changes: 3 additions & 3 deletions e2e/serial/swap/1_swapFlow1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,16 +640,16 @@ it('should be able to filter assets to buy by network', async () => {
await typeOnTextInput({
id: 'token-to-buy-search-token-input',
driver,
text: 'matic',
text: 'pol',
});
await delayTime('long');
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.MATIC_POLYGON_ID}-favorites-token-to-buy-row`,
id: `${SWAP_VARIABLES.POL_POLYGON_ID}-favorites-token-to-buy-row`,
driver,
});
// ARBITRUM
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.MATIC_POLYGON_ID}-token-to-buy-token-input-remove`,
id: `${SWAP_VARIABLES.POL_POLYGON_ID}-token-to-buy-token-input-remove`,
driver,
});
await findElementByTestIdAndClick({
Expand Down
2 changes: 1 addition & 1 deletion e2e/walletVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SWAP_VARIABLES = {
ETH_MAINNET_ID: 'eth_1',
ETH_OPTIMISM_ID: '0x0000000000000000000000000000000000000000_10',
GMX_ARBITRUM_ID: '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a_42161',
MATIC_POLYGON_ID: '0x0000000000000000000000000000000000001010_137',
POL_POLYGON_ID: '0x0000000000000000000000000000000000001010_137',
OP_OPTIMISM_ID: '0x4200000000000000000000000000000000000042_10',
UNI_BNB_ID: '0xbf5140a22578168fd562dccf235e5d43a02ce9b1_56',
USDC_ARBITRUM_ID: '0xaf88d065e77c8cc2239327c5edb3a432268e5831_42161',
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "browser-extension",
"license": "GPL-3.0-only",
"version": "1.5.38",
"version": "1.5.39",
"scripts": {
"//enable dev mode": "",
"devmode:on": "sed -i'' -e 's/IS_DEV.*/IS_DEV=true/g' .env",
Expand Down Expand Up @@ -277,7 +277,9 @@
"braces": "3.0.3",
"ws": "8.17.1",
"micromatch": "4.0.8",
"webpack": "5.94.0"
"webpack": "5.94.0",
"path-to-regexp": "6.3.0",
"dset": "3.1.4"
},
"lavamoat": {
"allowScripts": {
Expand Down
6 changes: 2 additions & 4 deletions src/core/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export const ETH_ADDRESS = 'eth';
export const DAI_ADDRESS = '0x6b175474e89094c44da98b954eedeac495271d0f';
export const USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
export const WBTC_ADDRESS = '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599';
export const MATIC_MAINNET_ADDRESS =
'0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0';
export const POL_MAINNET_ADDRESS = '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6';
export const BNB_MAINNET_ADDRESS = '0xb8c77482e45f1f44de1745f52c74426c631bdd52';
export const SOCKS_ADDRESS = '0x23b608675a2b2fb1890d3abbd85c5775c51691d5';
export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
Expand Down Expand Up @@ -84,8 +83,7 @@ export const DAI_BSC_ADDRESS = '0x6b175474e89094c44da98b954eedeac495271d0f';
export const USDC_BSC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';

// polygon
export const MATIC_POLYGON_ADDRESS =
'0x0000000000000000000000000000000000001010';
export const POL_POLYGON_ADDRESS = '0x0000000000000000000000000000000000001010';
export const WETH_POLYGON_ADDRESS =
'0x7ceb23fd6bc0add59e62ac25578270cff1b9f619';
export const DAI_POLYGON_ADDRESS = '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063';
Expand Down
2 changes: 1 addition & 1 deletion src/core/resources/addys/addysSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface AddySummary {
[key: Address]: {
summary: {
native_balance_by_symbol: {
[key in 'ETH' | 'MATIC' | 'BNB' | 'AVAX']: {
[key in 'ETH' | 'POL' | 'BNB' | 'AVAX']: {
symbol: string;
quantity: string;
decimals: number;
Expand Down
4 changes: 2 additions & 2 deletions src/core/state/favorites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
ETH_BLAST_ADDRESS,
ETH_OPTIMISM_ADDRESS,
ETH_ZORA_ADDRESS,
MATIC_POLYGON_ADDRESS,
OP_ADDRESS,
POL_POLYGON_ADDRESS,
SOCKS_ADDRESS,
SOCKS_ARBITRUM_ADDRESS,
USDB_BLAST_ADDRESS,
Expand Down Expand Up @@ -77,7 +77,7 @@ const defaultFavorites = {
],
[ChainId.bsc]: [BNB_BSC_ADDRESS, DAI_BSC_ADDRESS, USDC_BSC_ADDRESS],
[ChainId.polygon]: [
MATIC_POLYGON_ADDRESS,
POL_POLYGON_ADDRESS,
WETH_POLYGON_ADDRESS,
DAI_POLYGON_ADDRESS,
USDC_POLYGON_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion src/core/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type BaseTransaction = {
direction?: TransactionDirection;
flashbots?: boolean;

value?: string; // network asset amount sent with the tx (like eth or matic)
value?: string; // network asset amount sent with the tx (like eth or pol)
fee?: string;
native?: {
// fee and value but in the user prefered currency terms (USD, EUR, etc)
Expand Down
19 changes: 13 additions & 6 deletions src/core/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ const parseFees = (
const feeValue = FixedNumber.from(
formatUnits(BigInt(fee.value) + rollupFee, nativeAssetDecimals),
);
const feePrice = FixedNumber.fromString(fee.price.toString());
const feePrice = FixedNumber.fromString(
fee.price.toFixed(nativeAssetDecimals).toString(),
nativeAssetDecimals,
);

return {
fee: feeValue.toString(),
Expand Down Expand Up @@ -278,19 +281,23 @@ export function parseTransaction({
const description = getDescription(asset, type, meta);

const nativeAsset = changes.find((change) => change?.asset.isNativeAsset);
const nativeAssetPrice = FixedNumber.fromString(
nativeAsset?.price?.toString() || '0',
);

const value = FixedNumber.fromValue(
BigNumber.from(nativeAsset?.value || 0),
nativeAsset?.asset.decimals || 0,
);

const valueInNative = value.mulUnsafe(nativeAssetPrice).toString();

const nativeAssetDecimals = 18; // we only support networks with 18 decimals native assets rn, backend will change when we support more

const nativeAssetPrice = FixedNumber.fromString(
typeof nativeAsset?.price === 'number'
? nativeAsset.price.toFixed(nativeAssetDecimals).toString()
: '0',
nativeAssetDecimals,
);

const valueInNative = value.mulUnsafe(nativeAssetPrice).toString();

const { feeInNative, ...fee } = parseFees(tx.fee, nativeAssetDecimals);

const native = {
Expand Down
39 changes: 23 additions & 16 deletions src/entries/popup/components/TransactionFee/TransactionFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { SwitchTransactionSpeedMenu } from './TransactionSpeedsMenu';

type FeeProps = {
chainId: ChainId;
disableShortcuts?: boolean;
accentColor?: string;
plainTriggerBorder?: boolean;
selectedSpeed: GasSpeed;
Expand All @@ -71,6 +72,7 @@ function Fee({
analyticsEvents,
baseFeeTrend,
chainId,
disableShortcuts,
currentBaseFee,
gasFeeParamsBySpeed,
isLoading,
Expand Down Expand Up @@ -130,22 +132,24 @@ function Fee({

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.global.OPEN_CUSTOM_GAS_MENU.key) {
if (chainId === ChainId.mainnet) {
trackShortcut({
key: shortcuts.global.OPEN_CUSTOM_GAS_MENU.display,
type: 'customGasMenu.open',
});
// hackery preventing GweiInputMask from firing an onChange event when opening the menu with KB
setTimeout(() => openCustomGasSheet(), 0);
}
} else if (e.key === shortcuts.global.OPEN_GAS_MENU.key) {
if (chainId === ChainId.mainnet || chainId === ChainId.polygon) {
trackShortcut({
key: shortcuts.global.OPEN_GAS_MENU.display,
type: 'gasMenu.open',
});
switchTransactionSpeedMenuRef?.current?.open();
if (!disableShortcuts) {
if (e.key === shortcuts.global.OPEN_CUSTOM_GAS_MENU.key) {
if (chainId === ChainId.mainnet) {
trackShortcut({
key: shortcuts.global.OPEN_CUSTOM_GAS_MENU.display,
type: 'customGasMenu.open',
});
// hackery preventing GweiInputMask from firing an onChange event when opening the menu with KB
setTimeout(() => openCustomGasSheet(), 0);
}
} else if (e.key === shortcuts.global.OPEN_GAS_MENU.key) {
if (chainId === ChainId.mainnet || chainId === ChainId.polygon) {
trackShortcut({
key: shortcuts.global.OPEN_GAS_MENU.display,
type: 'gasMenu.open',
});
switchTransactionSpeedMenuRef?.current?.open();
}
}
}
},
Expand Down Expand Up @@ -256,6 +260,7 @@ function Fee({

type TransactionFeeProps = {
chainId: ChainId;
disableShortcuts?: boolean;
address?: Address;
defaultSpeed?: GasSpeed;
transactionRequest: TransactionRequest;
Expand All @@ -271,6 +276,7 @@ type TransactionFeeProps = {

export function TransactionFee({
chainId,
disableShortcuts,
address,
defaultSpeed,
transactionRequest,
Expand Down Expand Up @@ -302,6 +308,7 @@ export function TransactionFee({
return (
<Fee
analyticsEvents={analyticsEvents}
disableShortcuts={disableShortcuts}
chainId={chainId}
accentColor={accentColor}
plainTriggerBorder={plainTriggerBorder}
Expand Down
17 changes: 7 additions & 10 deletions src/entries/popup/hooks/useWalletsSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const parseAddressSummary = ({
const {
ETH: ethRawBalance,
BNB: bnbRawBalance,
MATIC: maticRawBalance,
POL: polRawBalance,
AVAX: avaxRawBalance,
} = addressData?.summary.native_balance_by_symbol || {};

Expand All @@ -69,14 +69,11 @@ const parseAddressSummary = ({
currentCurrency,
).amount;

const maticBalance = convertRawAmountToBalance(
maticRawBalance?.quantity || 0,
{
decimals: 18,
},
).amount;
const maticCurrencyBalance = convertAmountAndPriceToNativeDisplay(
maticBalance || 0,
const polBalance = convertRawAmountToBalance(polRawBalance?.quantity || 0, {
decimals: 18,
}).amount;
const polCurrencyBalance = convertAmountAndPriceToNativeDisplay(
polBalance || 0,
nativeAssets?.[ChainId.polygon]?.price?.value || 0,
currentCurrency,
).amount;
Expand All @@ -92,7 +89,7 @@ const parseAddressSummary = ({

const balance = add(
add(ethCurrencyBalance, bnbCurrencyBalance),
add(maticCurrencyBalance, avaxCurrencyBalance),
add(polCurrencyBalance, avaxCurrencyBalance),
);

const balanceDisplay = convertAmountToNativeDisplay(balance, currentCurrency);
Expand Down
77 changes: 40 additions & 37 deletions src/entries/popup/pages/send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,49 +550,51 @@ export function Send() {

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.altKey) {
if (e.key === shortcuts.send.FOCUS_TO_ADDRESS.key) {
trackShortcut({
key: shortcuts.send.FOCUS_TO_ADDRESS.display,
type: 'send.focusToAddress',
});
toAddressInputRef?.current?.focus();
sendTokenInputRef?.current?.blur();
}
if (e.key === shortcuts.send.FOCUS_ASSET.key) {
trackShortcut({
key: shortcuts.send.FOCUS_ASSET.display,
type: 'send.focusAsset',
});
toAddressInputRef?.current?.blur();
sendTokenInputRef.current?.focus();
}
} else {
if (!toAddressInputRef.current?.isFocused?.()) {
if (e.key === shortcuts.send.SET_MAX_AMOUNT.key) {
if (!explainerSheetParams.show && !contactSaveAction.show) {
if (e.altKey) {
if (e.key === shortcuts.send.FOCUS_TO_ADDRESS.key) {
trackShortcut({
key: shortcuts.send.SET_MAX_AMOUNT.display,
type: 'send.setMax',
key: shortcuts.send.FOCUS_TO_ADDRESS.display,
type: 'send.focusToAddress',
});
setMaxAssetAmount();
toAddressInputRef?.current?.focus();
sendTokenInputRef?.current?.blur();
}
if (e.key === shortcuts.send.SWITCH_CURRENCY_LABEL.key) {
if (e.key === shortcuts.send.FOCUS_ASSET.key) {
trackShortcut({
key: shortcuts.send.SWITCH_CURRENCY_LABEL.display,
type: 'send.switchCurrency',
key: shortcuts.send.FOCUS_ASSET.display,
type: 'send.focusAsset',
});
switchIndependentField();
toAddressInputRef?.current?.blur();
sendTokenInputRef.current?.focus();
}
} else {
if (!toAddressInputRef.current?.isFocused?.()) {
if (e.key === shortcuts.send.SET_MAX_AMOUNT.key) {
trackShortcut({
key: shortcuts.send.SET_MAX_AMOUNT.display,
type: 'send.setMax',
});
setMaxAssetAmount();
}
if (e.key === shortcuts.send.SWITCH_CURRENCY_LABEL.key) {
trackShortcut({
key: shortcuts.send.SWITCH_CURRENCY_LABEL.display,
type: 'send.switchCurrency',
});
switchIndependentField();
}
}
if (
e.key === shortcuts.send.OPEN_CONTACT_MENU.key &&
!valueInputRef.current?.isFocused?.()
) {
trackShortcut({
key: shortcuts.send.OPEN_CONTACT_MENU.display,
type: 'send.openContactMenu',
});
clickHeaderRight();
}
}
if (
e.key === shortcuts.send.OPEN_CONTACT_MENU.key &&
!valueInputRef.current?.isFocused?.()
) {
trackShortcut({
key: shortcuts.send.OPEN_CONTACT_MENU.display,
type: 'send.openContactMenu',
});
clickHeaderRight();
}
}
},
Expand Down Expand Up @@ -753,6 +755,7 @@ export function Send() {
<Rows space="20px">
<Row>
<TransactionFee
disableShortcuts={contactSaveAction.show}
chainId={chainId}
transactionRequest={transactionRequestForGas}
accentColor={assetAccentColor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const SwapReviewSheetWithQuote = ({
setSendingSwap(false);

if (swapExecutedSuccessfully) {
navigate(ROUTES.HOME, { state: { tab: 'activity' } });
navigate(ROUTES.HOME, { state: { tab: 'tokens' } });
}
}, [
assetToBuy,
Expand Down
8 changes: 6 additions & 2 deletions src/entries/popup/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,9 @@ export function Swap({ bridge = false }: { bridge?: boolean }) {
}
setAssetToSellInputValue={setAssetToSellInputValue}
inputRef={assetToSellInputRef}
openDropdownOnMount={inputToOpenOnMount === 'sell'}
openDropdownOnMount={
inputToOpenOnMount === 'sell' && !assetToSell
}
assetToSellNativeValue={assetToSellNativeValue}
assetToSellNativeDisplay={assetToSellNativeDisplay}
setAssetToSellInputNativeValue={
Expand Down Expand Up @@ -881,7 +883,9 @@ export function Swap({ bridge = false }: { bridge?: boolean }) {
assetToSellValue={assetToSellValue}
setAssetToBuyInputValue={setAssetToBuyInputValue}
inputRef={assetToBuyInputRef}
openDropdownOnMount={inputToOpenOnMount === 'buy'}
openDropdownOnMount={
inputToOpenOnMount === 'buy' && !assetToBuy
}
inputDisabled={isCrosschainSwap}
assetToBuyNativeDisplay={assetToBuyNativeDisplay}
assetToSellNativeDisplay={assetToSellNativeDisplay}
Expand Down
Loading

0 comments on commit d75df08

Please sign in to comment.