Skip to content

Commit

Permalink
merge main and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ffmcgee725 committed Jan 30, 2025
2 parents dbce84a + 6ca9116 commit 3eb6ade
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 42 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build storybook

on:
workflow_call:
secrets:
STORYBOOK_TOKEN:
required: true

jobs:
build-storybook:
Expand Down Expand Up @@ -30,5 +33,5 @@ jobs:
# For a `push` event, the branch is `github.ref_name`.
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
run: |
git remote add storybook git@github.com:MetaMask/metamask-storybook.git
git remote add storybook https://${{ secrets.STORYBOOK_TOKEN }}@github.com/MetaMask/metamask-storybook.git
yarn storybook:deploy
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ jobs:
build-storybook:
name: Build storybook
uses: ./.github/workflows/build-storybook.yml
secrets:
STORYBOOK_TOKEN: ${{ secrets.STORYBOOK_TOKEN }}
permissions:
contents: read
# id-token permission is required for uploading to s3
Expand Down
4 changes: 2 additions & 2 deletions development/get-next-semver-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VERSION_PACKAGE=$(node -p "require('./package.json').version")
# Compare versions and keep the highest one
HIGHEST_VERSION=$(printf "%s\n%s\n%s" "$VERSION_BRANCHES" "$VERSION_TAGS" "$VERSION_PACKAGE" | sort --version-sort | tail -n 1)

# Increment the minor version of the highest version found
NEXT_VERSION=$(echo "$HIGHEST_VERSION" | awk -F. -v OFS=. '{$2++; print}')
# Increment the minor version of the highest version found and reset the patch version to 0
NEXT_VERSION=$(echo "$HIGHEST_VERSION" | awk -F. -v OFS=. '{$2++; $3=0; print}')

echo "NEXT_SEMVER_VERSION=${NEXT_VERSION}" >> "$GITHUB_ENV"
7 changes: 6 additions & 1 deletion lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,14 @@
"Document.prototype": true,
"DocumentFragment.prototype": true,
"Element.prototype": true,
"Event.prototype": true,
"EventTarget.prototype": true,
"NavigateEvent.prototype": true,
"NavigationDestination.prototype": true,
"Node.prototype": true,
"console.warn": true,
"document": true
"document": true,
"navigation": true
},
"packages": {
"react": true
Expand Down
7 changes: 6 additions & 1 deletion lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,14 @@
"Document.prototype": true,
"DocumentFragment.prototype": true,
"Element.prototype": true,
"Event.prototype": true,
"EventTarget.prototype": true,
"NavigateEvent.prototype": true,
"NavigationDestination.prototype": true,
"Node.prototype": true,
"console.warn": true,
"document": true
"document": true,
"navigation": true
},
"packages": {
"react": true
Expand Down
7 changes: 6 additions & 1 deletion lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,14 @@
"Document.prototype": true,
"DocumentFragment.prototype": true,
"Element.prototype": true,
"Event.prototype": true,
"EventTarget.prototype": true,
"NavigateEvent.prototype": true,
"NavigationDestination.prototype": true,
"Node.prototype": true,
"console.warn": true,
"document": true
"document": true,
"navigation": true
},
"packages": {
"react": true
Expand Down
7 changes: 6 additions & 1 deletion lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,14 @@
"Document.prototype": true,
"DocumentFragment.prototype": true,
"Element.prototype": true,
"Event.prototype": true,
"EventTarget.prototype": true,
"NavigateEvent.prototype": true,
"NavigationDestination.prototype": true,
"Node.prototype": true,
"console.warn": true,
"document": true
"document": true,
"navigation": true
},
"packages": {
"react": true
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@
"@fortawesome/fontawesome-free": "^5.13.0",
"@keystonehq/bc-ur-registry-eth": "^0.19.1",
"@keystonehq/metamask-airgapped-keyring": "^0.14.1",
"@lavamoat/lavadome-react": "0.0.17",
"@lavamoat/snow": "^2.0.2",
"@lavamoat/lavadome-react": "0.0.20",
"@lavamoat/snow": "^2.0.3",
"@material-ui/core": "^4.11.0",
"@metamask-institutional/custody-controller": "^0.3.0",
"@metamask-institutional/custody-keyring": "^2.1.1",
Expand Down Expand Up @@ -455,7 +455,7 @@
"@babel/register": "^7.25.9",
"@jest/globals": "^29.7.0",
"@lavamoat/allow-scripts": "^3.3.1",
"@lavamoat/lavadome-core": "0.0.10",
"@lavamoat/lavadome-core": "0.0.20",
"@lavamoat/lavapack": "^7.0.5",
"@lgbot/madge": "^6.2.0",
"@lydell/node-pty": "^1.0.1",
Expand Down
3 changes: 2 additions & 1 deletion test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"gas": "0x153e2",
"value": "0x0"
}
}
},
"maxValueMode": {}
},
"history": {
"mostRecentOverviewPage": "/mostRecentOverviewPage"
Expand Down
21 changes: 17 additions & 4 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,13 @@ class Driver {

const filepathBase = `${artifactDir(title)}/test-failure`;
await fs.mkdir(artifactDir(title), { recursive: true });

const windowHandles = await this.driver.getAllWindowHandles();
// On occasion there may be a bug in the offscreen document which does
// not render visibly to the user and therefore no screenshot can be
// taken. In this case we skip the screenshot and log the error.
try {
// If there's more than one tab open, we want to iterate through all of them and take a screenshot with a unique name
const windowHandles = await this.driver.getAllWindowHandles();
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const windowTitle = await this.driver.getTitle();
Expand All @@ -1252,12 +1253,24 @@ class Driver {
} catch (e) {
console.error('Failed to take screenshot', e);
}
const htmlSource = await this.driver.getPageSource();
await fs.writeFile(`${filepathBase}-dom.html`, htmlSource);

try {
for (const handle of windowHandles) {
const windowNumber = windowHandles.indexOf(handle) + 1;
await this.driver.switchTo().window(handle);

const htmlSource = await this.driver.getPageSource();
await fs.writeFile(
`${filepathBase}-dom-${windowNumber}.html`,
htmlSource,
);
}
} catch (e) {
console.error('Failed to capture DOM snapshot', e);
}

// We want to take a state snapshot of the app if possible, this is useful for debugging
try {
const windowHandles = await this.driver.getAllWindowHandles();
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const uiState = await this.driver.executeScript(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('useFeeCalculations', () => {
"maxFeeFiat": "< $0.01",
"maxFeeFiatWith18SignificantDigits": "0",
"maxFeeNative": "0 ETH",
"preciseNativeFeeInHex": "0x0",
}
`);
});
Expand Down Expand Up @@ -61,6 +62,7 @@ describe('useFeeCalculations', () => {
"maxFeeFiat": "$0.07",
"maxFeeFiatWith18SignificantDigits": null,
"maxFeeNative": "0.0001 ETH",
"preciseNativeFeeInHex": "0x3be226d2d900",
}
`);
});
Expand Down Expand Up @@ -92,6 +94,7 @@ describe('useFeeCalculations', () => {
"maxFeeFiat": "$0.07",
"maxFeeFiatWith18SignificantDigits": null,
"maxFeeNative": "0.0001 ETH",
"preciseNativeFeeInHex": "0x364ba3e2d900",
}
`);
});
Expand Down Expand Up @@ -122,6 +125,7 @@ describe('useFeeCalculations', () => {
"maxFeeFiat": "$0.07",
"maxFeeFiatWith18SignificantDigits": null,
"maxFeeNative": "0.0001 ETH",
"preciseNativeFeeInHex": "0x103be226d2d900",
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GasFeeEstimates } from '@metamask/gas-fee-controller';
import { TransactionMeta } from '@metamask/transaction-controller';
import { Hex } from '@metamask/utils';
import { add0x, Hex } from '@metamask/utils';
import { useCallback, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { EtherDenomination } from '../../../../../../../shared/constants/common';
Expand Down Expand Up @@ -80,6 +80,7 @@ export function useFeeCalculations(transactionMeta: TransactionMeta) {
currentCurrencyFee,
currentCurrencyFeeWith18SignificantDigits,
nativeCurrencyFee,
preciseNativeFeeInHex: add0x(hexFee),
};
},
[conversionRate, currentCurrency, fiatFormatter],
Expand Down Expand Up @@ -188,5 +189,6 @@ export function useFeeCalculations(transactionMeta: TransactionMeta) {
maxFeeFiat,
maxFeeFiatWith18SignificantDigits,
maxFeeNative,
preciseNativeFeeInHex: estimatedFees.preciseNativeFeeInHex,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { renderHook } from '@testing-library/react-hooks';
import { useDispatch, useSelector } from 'react-redux';
import { TransactionType } from '@metamask/transaction-controller';
import { updateEditableParams } from '../../../../../../store/actions';
import { useConfirmContext } from '../../../../context/confirm';
import { useFeeCalculations } from './useFeeCalculations';
import { useMaxValueRefresher } from './useMaxValueRefresher';

jest.mock('react-redux', () => ({
useDispatch: jest.fn(),
useSelector: jest.fn(),
}));

jest.mock('../../../../../../store/actions', () => ({
updateEditableParams: jest.fn(),
}));

jest.mock('../../../../context/confirm', () => ({
useConfirmContext: jest.fn(),
}));

jest.mock('../hooks/useFeeCalculations', () => ({
useFeeCalculations: jest.fn(),
}));

describe('useMaxValueRefresher', () => {
const dispatchMock = jest.fn();
const simpleSendTransactionMetaMock = {
id: '1',
type: TransactionType.simpleSend,
};

beforeEach(() => {
(useDispatch as jest.Mock).mockReturnValue(dispatchMock);
(useConfirmContext as jest.Mock).mockReturnValue({
currentConfirmation: simpleSendTransactionMetaMock,
});
jest.clearAllMocks();
});

it('updates transaction value in max amount mode for simpleSend', () => {
const balance = '0x111';
const preciseNativeFeeInHex = '0x001';
const newValue = '0x110';

(useSelector as jest.Mock)
.mockReturnValueOnce(balance)
.mockReturnValueOnce(true);

(useFeeCalculations as jest.Mock).mockReturnValue({
preciseNativeFeeInHex,
});

renderHook(() => useMaxValueRefresher());

expect(dispatchMock).toHaveBeenCalledWith(
updateEditableParams(simpleSendTransactionMetaMock.id, {
value: newValue,
}),
);
});

it('does not update transaction value if not in max amount mode', () => {
(useSelector as jest.Mock)
.mockReturnValueOnce('0x111')
.mockReturnValueOnce(false);

renderHook(() => useMaxValueRefresher());

expect(dispatchMock).not.toHaveBeenCalled();
});

it('does not update transaction value if transaction type is not simpleSend', () => {
const transactionMeta = { id: '1', type: 'otherType' };
(useConfirmContext as jest.Mock).mockReturnValue({
currentConfirmation: transactionMeta,
});

renderHook(() => useMaxValueRefresher());

expect(dispatchMock).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
TransactionType,
type TransactionMeta,
} from '@metamask/transaction-controller';
import { add0x } from '@metamask/utils';

import {
getSelectedAccountCachedBalance,
selectMaxValueModeForTransaction,
} from '../../../../../../selectors';
import { subtractHexes } from '../../../../../../../shared/modules/conversion.utils';
import { updateEditableParams } from '../../../../../../store/actions';
import { useConfirmContext } from '../../../../context/confirm';
import { useFeeCalculations } from './useFeeCalculations';

// This hook is used to refresh the max value of the transaction
// when the user is in max amount mode only for the transaction type simpleSend
// It subtracts the native fee from the balance and updates the value of the transaction
export const useMaxValueRefresher = () => {
const { currentConfirmation: transactionMeta } =
useConfirmContext<TransactionMeta>();
const dispatch = useDispatch();
const { preciseNativeFeeInHex } = useFeeCalculations(transactionMeta);
const balance = useSelector(getSelectedAccountCachedBalance);
const isMaxAmountMode = useSelector((state) =>
selectMaxValueModeForTransaction(state, transactionMeta?.id),
);

useEffect(() => {
if (
!isMaxAmountMode ||
transactionMeta.type !== TransactionType.simpleSend
) {
return;
}

const newValue = subtractHexes(balance, preciseNativeFeeInHex);
const newValueInHex = add0x(newValue);

dispatch(
updateEditableParams(transactionMeta.id, { value: newValueInHex }),
);
}, [isMaxAmountMode, balance, preciseNativeFeeInHex]);
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import React from 'react';
import { TransactionMeta } from '@metamask/transaction-controller';
import { useConfirmContext } from '../../../../context/confirm';
import { SimulationDetails } from '../../../simulation-details';
import { AdvancedDetails } from '../shared/advanced-details/advanced-details';
import { GasFeesSection } from '../shared/gas-fees-section/gas-fees-section';
import NativeSendHeading from '../shared/native-send-heading/native-send-heading';
import { TokenDetailsSection } from '../token-transfer/token-details-section';
import { TransactionFlowSection } from '../token-transfer/transaction-flow-section';
import { useMaxValueRefresher } from '../hooks/useMaxValueRefresher';

const NativeTransferInfo = () => {
const { currentConfirmation: transactionMeta } =
useConfirmContext<TransactionMeta>();
useMaxValueRefresher();

const isWalletInitiated = transactionMeta.origin === 'metamask';

Expand Down
7 changes: 7 additions & 0 deletions ui/selectors/confirm-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,10 @@ export const selectTransactionValue = createSelector(
(isMaxValueEnabled, maxValue, transactionMetadata) =>
isMaxValueEnabled ? maxValue : transactionMetadata?.txParams?.value,
);

const maxValueModeSelector = (state) => state.confirmTransaction.maxValueMode;

export function selectMaxValueModeForTransaction(state, transactionId) {
const maxValueModes = maxValueModeSelector(state);
return maxValueModes[transactionId];
}
Loading

0 comments on commit 3eb6ade

Please sign in to comment.