Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed May 21, 2024
1 parent 5b2d07d commit 3ee4229
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
2 changes: 1 addition & 1 deletion jest.config.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
// This ensures that Babel can resolve ESM exports correctly.
moduleNameMapper: {
'^@metamask/utils/(.+)$': [
'<rootDir>/node_modules/@metamask/utils/dist/$1.js',
'<rootDir>/node_modules/@metamask/utils/dist/$1.cjs',
],
},

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"pre-push": "yarn lint"
},
"resolutions": {
"@metamask/utils": "file:/Users/jongsun/Code/utils",
"@metamask/utils": "file:/Volumes/Code/metamask/utils",
"superstruct": "file:/Volumes/Code/metamask/superstruct",
"tsup@^8.0.2": "patch:tsup@npm%3A8.0.2#./.yarn/patches/tsup-npm-8.0.2-86e40f68a7.patch"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> {
}

if (hasIpfsTokenURI) {
tokenURI = getFormattedIpfsUrl(ipfsGateway, tokenURI, useIPFSSubdomains);
tokenURI = await getFormattedIpfsUrl(ipfsGateway, tokenURI, useIPFSSubdomains);
}

try {
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/assetsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import type { Hex } from '@metamask/utils';
import { remove0x } from '@metamask/utils';
import BN from 'bn.js';
import { CID } from 'multiformats';

import type { Nft, NftMetadata } from './NftController';
import type { AbstractTokenPricesService } from './token-prices-service';
Expand Down Expand Up @@ -179,10 +178,10 @@ export function removeIpfsProtocolPrefix(ipfsUrl: string) {
* @returns IFPS content identifier (cid) and sub path as string.
* @throws Will throw if the url passed is not ipfs.
*/
export function getIpfsCIDv1AndPath(ipfsUrl: string): {
export async function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{
cid: string;
path?: string;
} {
}> {
const url = removeIpfsProtocolPrefix(ipfsUrl);

// check if there is a path
Expand All @@ -191,6 +190,7 @@ export function getIpfsCIDv1AndPath(ipfsUrl: string): {
const cid = index !== -1 ? url.substring(0, index) : url;
const path = index !== -1 ? url.substring(index) : undefined;

const { CID } = await import('multiformats/cid');
// We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)
// because most cid v0s appear to be incompatible with IPFS subdomains
return {
Expand All @@ -207,14 +207,14 @@ export function getIpfsCIDv1AndPath(ipfsUrl: string): {
* @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.
* @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.
*/
export function getFormattedIpfsUrl(
export async function getFormattedIpfsUrl(
ipfsGateway: string,
ipfsUrl: string,
subdomainSupported: boolean,
): string {
): Promise<string> {
const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));
if (subdomainSupported) {
const { cid, path } = getIpfsCIDv1AndPath(ipfsUrl);
const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);
return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;
}
const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);
Expand Down
2 changes: 1 addition & 1 deletion packages/user-operation-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"@metamask/network-controller": "^18.1.0",
"@metamask/polling-controller": "^6.0.2",
"@metamask/rpc-errors": "^6.2.1",
"@metamask/superstruct": "^2.0.0",
"@metamask/transaction-controller": "^28.1.1",
"@metamask/utils": "^8.3.0",
"bn.js": "^5.2.1",
"immer": "^9.0.6",
"lodash": "^4.17.21",
"superstruct": "^1.0.3",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/user-operation-controller/src/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TransactionType } from '@metamask/transaction-controller';
import { isStrictHexString } from '@metamask/utils';
import type { Struct, StructError } from 'superstruct';
import type { Struct, StructError } from '@metamask/superstruct';
import {
assert,
boolean,
Expand All @@ -12,7 +10,9 @@ import {
optional,
refine,
string,
} from 'superstruct';
} from '@metamask/superstruct';
import { TransactionType } from '@metamask/transaction-controller';
import { isStrictHexString } from '@metamask/utils';

import { EMPTY_BYTES } from '../constants';
import type {
Expand Down
51 changes: 32 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,19 @@ __metadata:
languageName: node
linkType: hard

"@metamask/key-tree@npm:^9.1.0":
version: 9.1.0
resolution: "@metamask/key-tree@npm:9.1.0"
dependencies:
"@metamask/scure-bip39": ^2.1.1
"@metamask/utils": ^8.3.0
"@noble/curves": ^1.2.0
"@noble/hashes": ^1.3.2
"@scure/base": ^1.0.0
checksum: 02709493f87c4cf8ebe3b81a47d3239d4d0b15fd73ac877047d0907652ff740d307966392f6f31d2f7871ab84315dddb4310edbf4edb976941a53d4e9ae04404
languageName: node
linkType: hard

"@metamask/keyring-api@npm:^6.0.0, @metamask/keyring-api@npm:^6.1.0":
version: 6.1.0
resolution: "@metamask/keyring-api@npm:6.1.0"
Expand Down Expand Up @@ -3005,33 +3018,33 @@ __metadata:
languageName: node
linkType: hard

"@metamask/snaps-sdk@npm:^4.0.0, @metamask/snaps-sdk@npm:^4.0.1, @metamask/snaps-sdk@npm:^4.1.0":
version: 4.1.0
resolution: "@metamask/snaps-sdk@npm:4.1.0"
"@metamask/snaps-sdk@npm:^4.0.0, @metamask/snaps-sdk@npm:^4.0.1, @metamask/snaps-sdk@npm:^4.1.0, @metamask/snaps-sdk@npm:^4.2.0":
version: 4.2.0
resolution: "@metamask/snaps-sdk@npm:4.2.0"
dependencies:
"@metamask/key-tree": ^9.0.0
"@metamask/key-tree": ^9.1.0
"@metamask/providers": ^16.1.0
"@metamask/rpc-errors": ^6.2.1
"@metamask/utils": ^8.3.0
fast-xml-parser: ^4.3.4
superstruct: ^1.0.3
checksum: b8056b102c996bbe2e6229af6a6118f21c353a513d15a927c9dd67b48c4ca5b5bcf65d5114d8631e9e2662391a574c80d74845ffa25182dbc8fcb2ff09bf7325
checksum: f9b0e6d7600680183e69d419f5a802208fdc119c7d1226a74076f3b8b8c581850b135392c2f35c391305fc37406973afeb19d8909101580ec16b63fd2f200a8c
languageName: node
linkType: hard

"@metamask/snaps-utils@npm:^7.0.3, @metamask/snaps-utils@npm:^7.1.0, @metamask/snaps-utils@npm:^7.3.0":
version: 7.3.0
resolution: "@metamask/snaps-utils@npm:7.3.0"
version: 7.4.0
resolution: "@metamask/snaps-utils@npm:7.4.0"
dependencies:
"@babel/core": ^7.23.2
"@babel/types": ^7.23.0
"@metamask/base-controller": ^5.0.2
"@metamask/key-tree": ^9.0.0
"@metamask/key-tree": ^9.1.0
"@metamask/permission-controller": ^9.0.2
"@metamask/rpc-errors": ^6.2.1
"@metamask/slip44": ^3.1.0
"@metamask/snaps-registry": ^3.1.0
"@metamask/snaps-sdk": ^4.1.0
"@metamask/snaps-sdk": ^4.2.0
"@metamask/utils": ^8.3.0
"@noble/hashes": ^1.3.1
"@scure/base": ^1.1.1
Expand All @@ -3045,7 +3058,7 @@ __metadata:
ses: ^1.1.0
superstruct: ^1.0.3
validate-npm-package-name: ^5.0.0
checksum: e58bb4cbcc6c8f17d2bf18995eb75e13af296f3f6c7d97a5681d3d76097450ae49bba9c5ac134e41ae6e01bfb005d0bc4bb1256d421e46b6c56490fa1b9f25ab
checksum: 1fb072f7262fa0f6685c85a3b44ce75805a87c13449c871e4dde0f6ac3c8cc62cc18ac51ae7eabc399165353abe6d08f3f4ee419cb1fe80518a202423b51660a
languageName: node
linkType: hard

Expand Down Expand Up @@ -3126,6 +3139,7 @@ __metadata:
"@metamask/network-controller": ^18.1.0
"@metamask/polling-controller": ^6.0.2
"@metamask/rpc-errors": ^6.2.1
"@metamask/superstruct": ^2.0.0
"@metamask/transaction-controller": ^28.1.1
"@metamask/utils": ^8.3.0
"@types/jest": ^27.4.1
Expand All @@ -3134,7 +3148,6 @@ __metadata:
immer: ^9.0.6
jest: ^27.5.1
lodash: ^4.17.21
superstruct: ^1.0.3
ts-jest: ^27.1.4
typedoc: ^0.24.8
typedoc-plugin-missing-exports: ^2.0.0
Expand All @@ -3149,9 +3162,9 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/utils@file:/Users/jongsun/Code/utils::locator=%40metamask%2Fcore-monorepo%40workspace%3A.":
version: 8.3.0
resolution: "@metamask/utils@file:/Users/jongsun/Code/utils#/Users/jongsun/Code/utils::hash=fecedf&locator=%40metamask%2Fcore-monorepo%40workspace%3A."
"@metamask/utils@file:/Volumes/Code/metamask/utils::locator=%40metamask%2Fcore-monorepo%40workspace%3A.":
version: 8.4.0
resolution: "@metamask/utils@file:/Volumes/Code/metamask/utils#/Volumes/Code/metamask/utils::hash=d1b8aa&locator=%40metamask%2Fcore-monorepo%40workspace%3A."
dependencies:
"@ethereumjs/tx": ^4.2.0
"@metamask/superstruct": ^2.0.0
Expand All @@ -3162,7 +3175,7 @@ __metadata:
pony-cause: ^2.1.10
semver: ^7.5.4
uuid: ^9.0.1
checksum: 532cb1e667014072181d4f5a782f0758a377a632675cee2ffd5f38217c3c15b6537b79571f9adf0b111792e847330c7e932ac22dcd4cf291af222563cfb8ce50
checksum: d5fae4f37e4e876385b05c09640d1649cdf2414a2a9a1797f5fd65c688f80b39d8433a8c979ac0bb2116d88813c8f774c00b1b202d7d335a6603734ee9078683
languageName: node
linkType: hard

Expand Down Expand Up @@ -11602,10 +11615,10 @@ __metadata:
languageName: node
linkType: hard

"superstruct@npm:^1.0.3":
version: 1.0.4
resolution: "superstruct@npm:1.0.4"
checksum: 2e070994cc4998a753c3f0215449d6de01ffb8180e4f46527f559ffbc2ebcc40fcf428f545ccd355921ef2920db7d138a96258ae35c788e6c24b2aa8bb1695cb
"superstruct@file:/Volumes/Code/metamask/superstruct::locator=%40metamask%2Fcore-monorepo%40workspace%3A.":
version: 2.0.0
resolution: "superstruct@file:/Volumes/Code/metamask/superstruct#/Volumes/Code/metamask/superstruct::hash=4e1d2a&locator=%40metamask%2Fcore-monorepo%40workspace%3A."
checksum: 9f3ad3c74929e9f2274b1b28c1d19b4ef7c11c34d057f523b95de20e50dedc8e27740a14d1120a6a92e69f8af26be55ab2fcb36a6a01b3b9ec9ab9824105eeda
languageName: node
linkType: hard

Expand Down

0 comments on commit 3ee4229

Please sign in to comment.