Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/check-template-and-add-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@ on:
merge_group:

jobs:
is-fork-pull-request:
name: Determine whether this is a pull request from a fork
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request_target' }}
outputs:
IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }}
steps:
- uses: actions/checkout@v4
- name: Determine whether this PR is from a fork
id: is-fork
run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}

check-template-and-add-labels:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'merge_group' }} # Skip this step for merge_group events
needs: [is-fork-pull-request]
if: ${{ always() && github.event_name != 'merge_group' && (github.event_name == 'issues' || (github.event_name == 'pull_request_target' && needs.is-fork-pull-request.outputs.IS_FORK == 'false')) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1 # This retrieves only the latest commit.

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

Expand Down
13 changes: 13 additions & 0 deletions .yarn/patches/@ethereumjs-util-npm-9.1.0-7e85509408.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/cjs/account.js b/dist/cjs/account.js
index 9c7b96d50a1e1e9a08463e0be74f1462576b8b53..04f390b50c11a10b20971bccb46d212978c2ac89 100644
--- a/dist/cjs/account.js
+++ b/dist/cjs/account.js
@@ -476,7 +476,7 @@ const pubToAddress = function (pubKey, sanitize = false) {
// Only take the lower 160bits of the hash
return (0, keccak_js_1.keccak256)(pubKey).subarray(-20);
};
-exports.pubToAddress = pubToAddress;
+exports.pubToAddress = require('@metamask/native-utils').pubToAddress;
exports.publicToAddress = exports.pubToAddress;
/**
* Returns the ethereum public key of a given private key.
21 changes: 21 additions & 0 deletions .yarn/patches/@metamask-key-tree-npm-10.1.1-0bfab435ac.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/dist/curves/ed25519.cjs b/dist/curves/ed25519.cjs
index 3f6b0951c046dbda89f18edb7f17e6d23b839fc5..d2aee95598d942c0219128a77f6f83abdf206b80 100644
--- a/dist/curves/ed25519.cjs
+++ b/dist/curves/ed25519.cjs
@@ -14,6 +14,7 @@ const isValidPrivateKey = (_privateKey) => true;
exports.isValidPrivateKey = isValidPrivateKey;
exports.deriveUnhardenedKeys = false;
exports.publicKeyLength = 33;
+const nativeUtils = require('@metamask/native-utils')
const getGetPublicKey = () => {
let hasSetWindowSize = false;
const getPublicKey = (privateKey, _compressed) => {
@@ -21,7 +22,7 @@ const getGetPublicKey = () => {
ed25519_1.ed25519.ExtendedPoint.BASE._setWindowSize(4);
hasSetWindowSize = true;
}
- const publicKey = ed25519_1.ed25519.getPublicKey(privateKey);
+ const publicKey = nativeUtils.getPublicKeyEd25519(privateKey);
return (0, utils_1.concatBytes)([new Uint8Array([0]), publicKey]);
};
return getPublicKey;
42 changes: 42 additions & 0 deletions app/__mocks__/@metamask/native-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-commonjs */
/**
* Mock for @metamask/native-utils
*
* This module uses react-native-nitro-modules which requires native code.
* In Jest tests, we use the original JavaScript implementations from @noble packages.
*/

const { secp256k1 } = require('@noble/curves/secp256k1');
const { ed25519 } = require('@noble/curves/ed25519');
const { keccak_256 } = require('@noble/hashes/sha3');
const { hmac } = require('@noble/hashes/hmac');
const { sha512 } = require('@noble/hashes/sha2');

export const getPublicKey = secp256k1.getPublicKey;
export const keccak256 = keccak_256;
export const hmacSha512 = (key, data) => hmac(sha512, key, data);
export const getPublicKeyEd25519 = ed25519.getPublicKey;
export const multiply = (a, b) => a * b;

/**
* Reimplemented from @ethereumjs/util.
*
* We cannot import pubToAddress from @ethereumjs/util directly because it's
* patched to use @metamask/native-utils, which would cause infinite recursion:
* 1. Our mock's pubToAddress is called
* 2. It requires @ethereumjs/util
* 3. @ethereumjs/util's exports.pubToAddress = require('@metamask/native-utils').pubToAddress
* 4. That returns our mock's pubToAddress
* 5. We call ourselves → stack overflow
*/
export const pubToAddress = (pubKey, sanitize = false) => {
let key = pubKey;
if (sanitize && pubKey.length !== 64) {
key = secp256k1.ProjectivePoint.fromHex(pubKey).toRawBytes(false).slice(1);
}
if (key.length !== 64) {
throw new Error('Expected pubKey to be of length 64');
}
return keccak_256(key).subarray(-20);
};
10 changes: 10 additions & 0 deletions app/components/UI/FundActionMenu/FundActionMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ describe('FundActionMenu', () => {
text: 'Buy',
location: 'FundActionMenu',
chain_id_destination: 1,
region: undefined,
ramp_routing: undefined,
is_authenticated: false,
preferred_provider: undefined,
order_count: 0,
});
expect(mockTrackEvent).toHaveBeenCalledWith(mockBuild());
});
Expand Down Expand Up @@ -536,6 +541,11 @@ describe('FundActionMenu', () => {
text: 'Buy',
location: 'FundActionMenu',
chain_id_destination: 137,
region: undefined,
ramp_routing: undefined,
is_authenticated: false,
preferred_provider: undefined,
order_count: 0,
});
});
});
Expand Down
24 changes: 18 additions & 6 deletions app/components/UI/FundActionMenu/FundActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const FundActionMenu = () => {
const rampUnifiedV1Enabled = useRampsUnifiedV1Enabled();
const { goToBuy, goToAggregator, goToSell, goToDeposit } =
useRampNavigation();
const depositButtonClickData = useRampsButtonClickData();
const rampsButtonClickData = useRampsButtonClickData();

const closeBottomSheetAndNavigate = useCallback(
(navigateFunc: () => void) => {
Expand Down Expand Up @@ -119,6 +119,10 @@ const FundActionMenu = () => {
location: 'FundActionMenu',
chain_id_destination: getChainIdForAsset(),
region: rampGeodetectedRegion,
ramp_routing: rampsButtonClickData.ramp_routing,
is_authenticated: rampsButtonClickData.is_authenticated,
preferred_provider: rampsButtonClickData.preferred_provider,
order_count: rampsButtonClickData.order_count,
},
navigationAction: () => {
if (customOnBuy) {
Expand All @@ -142,10 +146,10 @@ const FundActionMenu = () => {
chain_id_destination: getDecimalChainId(chainId),
ramp_type: 'DEPOSIT',
region: rampGeodetectedRegion,
ramp_routing: depositButtonClickData.ramp_routing,
is_authenticated: depositButtonClickData.is_authenticated,
preferred_provider: depositButtonClickData.preferred_provider,
order_count: depositButtonClickData.order_count,
ramp_routing: rampsButtonClickData.ramp_routing,
is_authenticated: rampsButtonClickData.is_authenticated,
preferred_provider: rampsButtonClickData.preferred_provider,
order_count: rampsButtonClickData.order_count,
},
traceName: TraceName.LoadDepositExperience,
navigationAction: () => goToDeposit(),
Expand All @@ -163,6 +167,10 @@ const FundActionMenu = () => {
location: 'FundActionMenu',
chain_id_destination: getChainIdForAsset(),
region: rampGeodetectedRegion,
ramp_routing: rampsButtonClickData.ramp_routing,
is_authenticated: rampsButtonClickData.is_authenticated,
preferred_provider: rampsButtonClickData.preferred_provider,
order_count: rampsButtonClickData.order_count,
},
traceName: TraceName.LoadRampExperience,
traceProperties: { tags: { rampType: RampType.BUY } },
Expand All @@ -188,6 +196,10 @@ const FundActionMenu = () => {
location: 'FundActionMenu',
chain_id_source: getDecimalChainId(chainId),
region: rampGeodetectedRegion,
ramp_routing: rampsButtonClickData.ramp_routing,
is_authenticated: rampsButtonClickData.is_authenticated,
preferred_provider: rampsButtonClickData.preferred_provider,
order_count: rampsButtonClickData.order_count,
},
traceName: TraceName.LoadRampExperience,
traceProperties: { tags: { rampType: RampType.SELL } },
Expand All @@ -208,7 +220,7 @@ const FundActionMenu = () => {
goToAggregator,
goToSell,
goToDeposit,
depositButtonClickData,
rampsButtonClickData,
],
);

Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/FundActionMenu/FundActionMenu.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ActionConfig {
isVisible: boolean;
isDisabled?: boolean;
analyticsEvent: IMetaMetricsEvent;
analyticsProperties: Record<string, string | number>;
analyticsProperties: Record<string, string | number | boolean | undefined>;
traceName: TraceName;
traceProperties?: Record<
string,
Expand Down
Loading
Loading