Skip to content

Commit

Permalink
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
Browse files Browse the repository at this point in the history
…-balances' into remove-portfolio-view-fallout
  • Loading branch information
NidhiKJha authored Nov 14, 2024
2 parents 81be764 + 8e57813 commit aa383a6
Show file tree
Hide file tree
Showing 34 changed files with 251 additions and 292 deletions.
1 change: 0 additions & 1 deletion .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ ignores:
- 'crypto-browserify' # polyfill
- 'process' # polyfill
- 'stream-http' # polyfill
- 'rimraf' # misc: install helper
- 'json-schema-to-ts' # misc: typescript helper
- 'https-browserify' # polyfill
- 'path-browserify' # polyfill
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ async function buildEventFragmentProperties({
}
const isRedesignedConfirmationsDeveloperSettingEnabled =
transactionMetricsRequest.getIsRedesignedConfirmationsDeveloperEnabled() ||
Boolean(process.env.ENABLE_CONFIRMATION_REDESIGN);
process.env.ENABLE_CONFIRMATION_REDESIGN === 'true';

const isRedesignedTransactionsUserSettingEnabled =
transactionMetricsRequest.getRedesignedTransactionsEnabled();
Expand Down
6 changes: 4 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6587,10 +6587,12 @@ export default class MetamaskController extends EventEmitter {
);
},
getRedesignedConfirmationsEnabled: () => {
return this.preferencesController.getRedesignedConfirmationsEnabled;
return this.preferencesController.state.preferences
.redesignedConfirmationsEnabled;
},
getRedesignedTransactionsEnabled: () => {
return this.preferencesController.getRedesignedTransactionsEnabled;
return this.preferencesController.state.preferences
.redesignedTransactionsEnabled;
},
getMethodData: (data) => {
if (!data) {
Expand Down
26 changes: 26 additions & 0 deletions development/clear-webpack-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

const fs = require('node:fs/promises');
const path = require('node:path');

const WEBPACK_CACHE_DIRECTORY = path.resolve(
__dirname,
'..',
'node_modules',
'.cache',
'webpack',
);

/**
* Clear the Webpack cache.
*
* This is typically run in the `postinstall` npm/Yarn lifecycle script.
*/
async function main() {
await fs.rm(WEBPACK_CACHE_DIRECTORY, { force: true, recursive: true });
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
11 changes: 10 additions & 1 deletion development/generate-attributions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ main() {
# relative to the project root irrespective of where this script was run.
cd "${PROJECT_DIRECTORY}"

# Remove allow-scripts plugin.
# Allow-scripts won't run correctly after a production-only install because the configuration
# includes exact paths to each dependency, and those paths can change in a production-only
# install because of the hoisting algorithm.
# We don't need postinstall scripts to run in order to generate attributions anyway.
yarn plugin remove @yarnpkg/plugin-allow-scripts

# Instruct Yarn to only install production dependencies
yarn workspaces focus --production

Expand All @@ -38,7 +45,9 @@ main() {

# Check if the script is running in a CI environment (GitHub Actions sets the CI variable to true)
if [ -z "${CI:-}" ]; then
# If not running in CI, restore development dependencies
# If not running in CI, restore the allow-scripts plugin and development dependencies.
cd "${PROJECT_DIRECTORY}"
git checkout -- .yarnrc.yml .yarn
yarn
fi
}
Expand Down
18 changes: 2 additions & 16 deletions lavamoat/build-system/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3175,22 +3175,8 @@
"__dirname": true
},
"packages": {
"eslint>file-entry-cache>flat-cache>flatted": true,
"eslint>file-entry-cache>flat-cache>rimraf": true
}
},
"eslint>file-entry-cache>flat-cache>rimraf": {
"builtin": {
"assert": true,
"fs": true,
"path.join": true
},
"globals": {
"process.platform": true,
"setTimeout": true
},
"packages": {
"nyc>glob": true
"del>rimraf": true,
"eslint>file-entry-cache>flat-cache>flatted": true
}
},
"eslint>glob-parent": {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"webpack": "tsx ./development/webpack/launch.ts",
"webpack:clearcache": "rimraf node_modules/.cache/webpack",
"webpack:clearcache": "./development/clear-webpack-cache.js",
"postinstall": "yarn webpack:clearcache",
"env:e2e": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn",
"start": "yarn build:dev dev --apply-lavamoat=false --snow=false",
Expand Down Expand Up @@ -647,7 +647,6 @@
"redux-mock-store": "^1.5.4",
"remote-redux-devtools": "^0.5.16",
"resolve-url-loader": "^3.1.5",
"rimraf": "^5.0.5",
"sass-embedded": "^1.71.0",
"sass-loader": "^14.1.1",
"schema-utils": "^4.2.0",
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/tests/confirmations/signatures/personal-sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'personal_sign',
);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');

await assertVerifiedPersonalMessage(driver, publicAddress);

await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'personal_sign',
);
await assertSignatureConfirmedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this:

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.delay(1000);

await assertInfoValues(driver);
await scrollAndConfirmAndAssertConfirm(driver);

await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'eth_signTypedData_v3',
);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await assertInfoValues(driver);
await scrollAndConfirmAndAssertConfirm(driver);
await assertSignatureConfirmedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'eth_signTypedData',
);

await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');
await driver.delay(1000);

await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'eth_signTypedData',
);
await assertSignatureConfirmedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/tests/confirmations/signatures/siwe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'personal_sign',
);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await assertInfoValues(driver);
await scrollAndConfirmAndAssertConfirm(driver);
Expand All @@ -56,6 +51,12 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {
driver,
'0xef8674a92d62a1876624547bdccaef6c67014ae821de18fa910fbff56577a65830f68848585b33d1f4b9ea1c3da1c1b11553b6aabe8446717daf7cd1e38a68271c',
);

await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'personal_sign',
);
await assertSignatureConfirmedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
Expand Down
2 changes: 2 additions & 0 deletions ui/components/app/assets/util/calculateTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function calculateTokenBalance({
5, // precision for native token balance
);
}
return '0';
} else {
const hexBalance =
selectedAccountTokenBalancesAcrossChains?.[chainId]?.[address];
Expand All @@ -41,6 +42,7 @@ export function calculateTokenBalance({
new BN(decimals),
);
}
return '0';
}

return balance;
Expand Down
1 change: 0 additions & 1 deletion ui/pages/asset/asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const Asset = () => {
if (nft) {
content = <NftDetails nft={nft} />;
} else if (token && chainId) {
console.log('foo');
if (token?.address) {
content = <TokenAsset chainId={chainId} token={token} />;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import { isHexString } from '@metamask/utils';
import { BigNumber } from 'bignumber.js';
import { isBoolean } from 'lodash';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { calcTokenAmount } from '../../../../../../../../shared/lib/transactions-controller-utils';
import { getIntlLocale } from '../../../../../../../ducks/locale/locale';
import { SPENDING_CAP_UNLIMITED_MSG } from '../../../../../constants';
import { toNonScientificString } from '../../hooks/use-token-values';
import { useDecodedTransactionData } from '../../hooks/useDecodedTransactionData';
import { useIsNFT } from './use-is-nft';

Expand All @@ -27,7 +26,7 @@ export const useApproveTokenSimulation = (

const decodedSpendingCap = useMemo(() => {
if (!value) {
return 0;
return '0';
}

const paramIndex = value.data[0].params.findIndex(
Expand All @@ -38,23 +37,24 @@ export const useApproveTokenSimulation = (
!isBoolean(param.value),
);
if (paramIndex === -1) {
return 0;
return '0';
}

return new BigNumber(value.data[0].params[paramIndex].value.toString())
.dividedBy(new BigNumber(10).pow(Number(decimals)))
.toNumber();
return calcTokenAmount(
value.data[0].params[paramIndex].value,
Number(decimals),
).toFixed();
}, [value, decimals]);

const formattedSpendingCap = useMemo(() => {
// formatting coerces small numbers to 0
return isNFT || decodedSpendingCap < 1
? toNonScientificString(decodedSpendingCap)
: new Intl.NumberFormat(locale).format(decodedSpendingCap);
return isNFT || parseInt(decodedSpendingCap, 10) < 1
? decodedSpendingCap
: new Intl.NumberFormat(locale).format(parseInt(decodedSpendingCap, 10));
}, [decodedSpendingCap, isNFT, locale]);

const spendingCap = useMemo(() => {
if (!isNFT && isSpendingCapUnlimited(decodedSpendingCap)) {
if (!isNFT && isSpendingCapUnlimited(parseInt(decodedSpendingCap, 10))) {
return SPENDING_CAP_UNLIMITED_MSG;
}
const tokenPrefix = isNFT ? '#' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mockState from '../../../../../../../test/data/mock-state.json';
import { renderHookWithConfirmContextProvider } from '../../../../../../../test/lib/confirmations/render-helpers';
import useTokenExchangeRate from '../../../../../../components/app/currency-input/hooks/useTokenExchangeRate';
import { useAssetDetails } from '../../../../hooks/useAssetDetails';
import { toNonScientificString, useTokenValues } from './use-token-values';
import { useTokenValues } from './use-token-values';
import { useDecodedTransactionData } from './useDecodedTransactionData';

jest.mock('../../../../hooks/useAssetDetails', () => ({
Expand Down Expand Up @@ -126,21 +126,3 @@ describe('useTokenValues', () => {
});
});
});

describe('toNonScientificString', () => {
const TEST_CASES = [
{ scientific: 1.23e-5, expanded: '0.0000123' },
{ scientific: 1e-10, expanded: '0.0000000001' },
{ scientific: 1.23e-21, expanded: '1.23e-21' },
];

// @ts-expect-error This is missing from the Mocha type definitions
it.each(TEST_CASES)(
'Expand $scientific to "$expanded"',
({ scientific, expanded }: { scientific: number; expanded: string }) => {
const actual = toNonScientificString(scientific);

expect(actual).toEqual(expanded);
},
);
});
Loading

0 comments on commit aa383a6

Please sign in to comment.