Skip to content

Commit

Permalink
Merge branch 'main' into brian/delete-linea
Browse files Browse the repository at this point in the history
  • Loading branch information
bergeron authored Jan 16, 2025
2 parents 7b813b8 + 4c43298 commit cb4070a
Show file tree
Hide file tree
Showing 42 changed files with 971 additions and 300 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,16 @@ jobs:
echo "All jobs passed step skipped. Block PR."
exit 1
fi
log-merge-group-failure:
name: Log merge group failure
# Only run this job if the merge group event fails, skip on forks
if: ${{ github.event_name == 'merge_group' && failure() && !github.event.repository.fork }}
needs:
- check-all-jobs-pass
uses: metamask/github-tools/.github/workflows/log-merge-group-failure.yml@6bbad335a01fce1a9ec1eabd9515542c225d46c0
secrets:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
SPREADSHEET_ID: ${{ secrets.GOOGLE_MERGE_QUEUE_SPREADSHEET_ID }}
SHEET_NAME: ${{ secrets.GOOGLE_MERGE_QUEUE_SHEET_NAME }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';

interface SelectedAsset {
isETH: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { selectInternalAccounts } from '../../../selectors/accountsController';
import Cell, {
CellVariant,
} from '../../../component-library/components/Cells/Cell';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { useStyles } from '../../../component-library/hooks';
import { TextColor } from '../../../component-library/components/Texts/Text';
import SensitiveText, {
Expand Down
32 changes: 25 additions & 7 deletions app/components/UI/SimulationDetails/formatAmount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { BigNumber } from 'bignumber.js';

const MIN_AMOUNT = new BigNumber('0.000001');
const PRECISION = 6;

// The default precision for displaying currency values.
// It set to the number of decimal places in the minimum amount.
export const DEFAULT_PRECISION = new BigNumber(MIN_AMOUNT).decimalPlaces();

// The number of significant decimals places to show for amounts less than 1.
const MAX_SIGNIFICANT_DECIMAL_PLACES = 3;
Expand All @@ -12,11 +15,21 @@ export function formatAmountMaxPrecision(
locale: string,
num: number | BigNumber,
): string {
return new Intl.NumberFormat(locale, {
minimumSignificantDigits: 1,
}).format(new BigNumber(num.toString()).toNumber());
const bigNumberValue = new BigNumber(num);
const numberOfDecimals = bigNumberValue.decimalPlaces();
const formattedValue = bigNumberValue.toFixed(numberOfDecimals ?? 0);

const [integerPart, fractionalPart] = formattedValue.split('.');
const formattedIntegerPart = new Intl.NumberFormat(locale).format(
integerPart as unknown as number,
);

return fractionalPart
? `${formattedIntegerPart}.${fractionalPart}`
: formattedIntegerPart;
}


/**
* Formats the a token amount with variable precision and significant
* digits.
Expand Down Expand Up @@ -65,21 +78,26 @@ export function formatAmount(locale: string, amount: BigNumber): string {
return new Intl.NumberFormat(locale, {
maximumSignificantDigits: MAX_SIGNIFICANT_DECIMAL_PLACES,
} as Intl.NumberFormatOptions).format(
amount.decimalPlaces(PRECISION).toNumber(),
amount.dp(DEFAULT_PRECISION ?? 0).toNumber(),
);
}

// Preserve all digits left of the decimal point.
// Cap the digits right of the decimal point: The more digits present
// on the left side of the decimal point, the less decimal places
// we show on the right side.
const digitsLeftOfDecimal = amount.abs().toFixed(0).length;
const digitsLeftOfDecimal = amount.abs().dp(0).toString().length;
const maximumFractionDigits = Math.max(
0,
MAX_SIGNIFICANT_DECIMAL_PLACES - digitsLeftOfDecimal + 1,
);

return new Intl.NumberFormat(locale, {
maximumFractionDigits,
} as Intl.NumberFormatOptions).format(amount.toNumber());
} as Intl.NumberFormatOptions).format(
// string is valid parameter for format function
// for some reason it gives TS issue
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format#number
amount.toFixed(maximumFractionDigits) as unknown as number,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
TotalFiatBalancesCrossChains,
useGetTotalFiatBalanceCrossChains,
} from '../../../../hooks/useGetTotalFiatBalanceCrossChains';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { getChainIdsToPoll } from '../../../../../selectors/tokensController';
import AggregatedPercentageCrossChains from '../../../../../component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains';

Expand Down
6 changes: 4 additions & 2 deletions app/components/Views/AccountActions/AccountActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useDispatch, useSelector } from 'react-redux';
import Share from 'react-native-share';

// External dependencies
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import BottomSheet, {
BottomSheetRef,
} from '../../../component-library/components/BottomSheets/BottomSheet';
Expand Down Expand Up @@ -397,7 +397,9 @@ const AccountActions = () => {
actionTitle={strings('accounts.remove_hardware_account')}
iconName={IconName.Close}
onPress={showRemoveHWAlert}
testID={AccountActionsBottomSheetSelectorsIDs.REMOVE_HARDWARE_ACCOUNT}
testID={
AccountActionsBottomSheetSelectorsIDs.REMOVE_HARDWARE_ACCOUNT
}
/>
)}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useMetrics } from '../../../components/hooks/useMetrics';

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { CaipChainId } from '@metamask/utils';
import { KeyringClient } from '@metamask/keyring-api';
import { KeyringClient } from '@metamask/keyring-snap-client';
import { BitcoinWalletSnapSender } from '../../../core/SnapKeyring/BitcoinWalletSnap';
import { MultichainNetworks } from '../../../core/Multichain/constants';
import { useSelector } from 'react-redux';
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/EditAccountName/EditAccountName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSelector } from 'react-redux';
import { SafeAreaView } from 'react-native';

// External dependencies
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import Text from '../../../component-library/components/Texts/Text/Text';
import { View } from 'react-native-animatable';
import { TextVariant } from '../../../component-library/components/Texts/Text';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import QRCode from 'react-native-qrcode-svg';
import { RouteProp, ParamListBase } from '@react-navigation/native';
import ScrollableTabView, {
Expand Down
18 changes: 11 additions & 7 deletions app/components/Views/RevealPrivateCredential/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react-native';
import configureMockStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { backgroundState } from '../../../util/test/initial-root-state';
import { RevealPrivateCredential } from './';
import { ThemeContext, mockTheme } from '../../../util/theme';
import { RevealSeedViewSelectorsIDs } from '../../../../e2e/selectors/Settings/SecurityAndPrivacy/RevealSeedView.selectors';
import { EthAccountType, EthMethod, EthScopes } from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
Expand Down Expand Up @@ -147,24 +149,26 @@ describe('RevealPrivateCredential', () => {

it('renders with a custom selectedAddress', async () => {
const mockInternalAccount: InternalAccount = {
type: 'eip155:eoa',
type: EthAccountType.Eoa,
id: 'unique-account-id-1',
address: '0x1234567890123456789012345678901234567890',
options: {
someOption: 'optionValue',
anotherOption: 42,
},
scopes: [EthScopes.Namespace],
methods: [
'personal_sign',
'eth_sign',
'eth_signTransaction',
'eth_sendTransaction',
EthMethod.PersonalSign,
EthMethod.SignTransaction,
EthMethod.SignTypedDataV1,
EthMethod.SignTypedDataV3,
EthMethod.SignTypedDataV4,
],
metadata: {
name: 'Test Account',
importTime: Date.now(),
keyring: {
type: 'HD Key Tree',
type: KeyringTypes.hd,
},
nameLastUpdatedAt: Date.now(),
snap: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import BottomSheet, {
import Text, {
TextVariant,
} from '../../../../component-library/components/Texts/Text';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import BannerAlert from '../../../../component-library/components/Banners/Banner/variants/BannerAlert';
import { BannerAlertSeverity } from '../../../../component-library/components/Banners/Banner';
import BottomSheetHeader from '../../../../component-library/components/BottomSheets/BottomSheetHeader';
Expand Down Expand Up @@ -170,56 +170,56 @@ export default function KeyringSnapRemovalWarning({
'app_settings.snaps.snap_settings.remove_account_snap_warning.banner_title',
)}
/>
{showConfirmation ? (
<>
<Text variant={TextVariant.BodyMD} style={styles.description}>
{`${strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_account_snap_alert_description_1',
)} `}
<Text variant={TextVariant.BodyMDBold}>
{snap.manifest.proposedName}
</Text>
{` ${strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_account_snap_alert_description_2',
)}`}
{showConfirmation ? (
<>
<Text variant={TextVariant.BodyMD} style={styles.description}>
{`${strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_account_snap_alert_description_1',
)} `}
<Text variant={TextVariant.BodyMDBold}>
{snap.manifest.proposedName}
</Text>
<TextInput
style={styles.input}
value={confirmationInput}
onChangeText={handleConfirmationInputChange}
testID={KEYRING_SNAP_REMOVAL_WARNING_TEXT_INPUT}
/>
{error && (
<Text variant={TextVariant.BodySM} style={styles.errorText}>
{strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_snap_error',
{
snapName: snap.manifest.proposedName,
},
)}
</Text>
)}
</>
) : (
<>
<Text variant={TextVariant.BodyMD} style={styles.description}>
{` ${strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_account_snap_alert_description_2',
)}`}
</Text>
<TextInput
style={styles.input}
value={confirmationInput}
onChangeText={handleConfirmationInputChange}
testID={KEYRING_SNAP_REMOVAL_WARNING_TEXT_INPUT}
/>
{error && (
<Text variant={TextVariant.BodySM} style={styles.errorText}>
{strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.description',
'app_settings.snaps.snap_settings.remove_account_snap_warning.remove_snap_error',
{
snapName: snap.manifest.proposedName,
},
)}
</Text>
<NativeViewGestureHandler disallowInterruption>
)}
</>
) : (
<>
<Text variant={TextVariant.BodyMD} style={styles.description}>
{strings(
'app_settings.snaps.snap_settings.remove_account_snap_warning.description',
)}
</Text>
<NativeViewGestureHandler disallowInterruption>
<ScrollView style={styles.scrollView}>
{accountListItems}
</ScrollView>
</NativeViewGestureHandler>
</>
)}
</View>
<BottomSheetFooter
style={styles.buttonContainer}
buttonsAlignment={ButtonsAlignment.Horizontal}
buttonPropsArray={buttonPropsArray}
/>
{accountListItems}
</ScrollView>
</NativeViewGestureHandler>
</>
)}
</View>
<BottomSheetFooter
style={styles.buttonContainer}
buttonsAlignment={ButtonsAlignment.Horizontal}
buttonPropsArray={buttonPropsArray}
/>
</BottomSheet>
);
}
Expand Down
11 changes: 6 additions & 5 deletions app/components/Views/Snaps/SnapSettings/SnapSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { selectPermissionControllerState } from '../../../../selectors/snaps/per
import KeyringSnapRemovalWarning from '../KeyringSnapRemovalWarning/KeyringSnapRemovalWarning';
import { getAccountsBySnapId } from '../../../../core/SnapKeyring/utils/getAccountsBySnapId';
import { selectInternalAccounts } from '../../../../selectors/accountsController';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import Logger from '../../../../util/Logger';
interface SnapSettingsProps {
snap: Snap;
Expand Down Expand Up @@ -100,7 +100,6 @@ const SnapSettings = () => {
setIsShowingSnapKeyringRemoveWarning(false);
}, []);


const removeSnap = useCallback(async () => {
const { SnapController } = Engine.context;
await SnapController.removeSnap(snap.id);
Expand All @@ -110,8 +109,11 @@ const SnapSettings = () => {
for (const keyringAccount of keyringAccounts) {
await Engine.removeAccount(keyringAccount.address);
}
} catch(error) {
Logger.error(error as Error, 'SnapSettings: failed to remove snap accounts when calling Engine.removeAccount');
} catch (error) {
Logger.error(
error as Error,
'SnapSettings: failed to remove snap accounts when calling Engine.removeAccount',
);
}
}
navigation.goBack();
Expand All @@ -125,7 +127,6 @@ const SnapSettings = () => {
}
}, [isKeyringSnap, keyringAccounts.length, removeSnap]);


const handleRemoveSnapKeyring = useCallback(() => {
try {
setIsShowingSnapKeyringRemoveWarning(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import React, { useCallback } from 'react';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { toChecksumHexAddress } from '@metamask/controller-utils';
import ButtonIcon, {
ButtonIconSizes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AddressBookControllerState } from '@metamask/address-book-controller';
import { NetworkType } from '@metamask/controller-utils';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import type { NetworkState } from '@metamask/network-controller';
import { Hex } from '@metamask/utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const SimulationValueDisplay: React.FC<
tokenDetails as TokenDetailsERC20,
);

const tokenAmount = isNumberValue(value) && !tokenId ? calcTokenAmount(value, tokenDecimals) : null;
const tokenAmount = isNumberValue(value) && !tokenId ? calcTokenAmount(value as number | string, tokenDecimals) : null;
const isValidTokenAmount = tokenAmount !== null && tokenAmount !== undefined && tokenAmount instanceof BigNumber;

const fiatValue = isValidTokenAmount && exchangeRate && !tokenId
Expand Down
2 changes: 1 addition & 1 deletion app/components/hooks/useAccounts/useAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
UseAccounts,
UseAccountsParams,
} from './useAccounts.types';
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { getChainIdsToPoll } from '../../../selectors/tokensController';
import { useGetFormattedTokensPerChain } from '../useGetFormattedTokensPerChain';
import { useGetTotalFiatBalanceCrossChains } from '../useGetTotalFiatBalanceCrossChains';
Expand Down
2 changes: 1 addition & 1 deletion app/components/hooks/useAccounts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InternalAccount } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { getFormattedAddressFromInternalAccount } from '../../../core/Multichain/utils';
import { BigNumber } from 'ethers';
import {
Expand Down
Loading

0 comments on commit cb4070a

Please sign in to comment.