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
61 changes: 10 additions & 51 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,6 @@
"count": 2
}
},
"packages/solana-wallet-snap/snap.config.ts": {
"import-x/no-nodejs-modules": {
"count": 1
},
"n/no-process-env": {
"count": 1
},
"no-restricted-globals": {
"count": 17
}
},
"packages/solana-wallet-snap/src/core/caching/useCache.test.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 4
Expand All @@ -181,9 +170,6 @@
"packages/solana-wallet-snap/src/core/clients/nft-api/NftApiClient.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 5
},
"no-unused-private-class-members": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/clients/price-api/PriceApiClient.test.ts": {
Expand Down Expand Up @@ -240,11 +226,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/handlers/onClientRequest/ClientRequestHandler.ts": {
"@typescript-eslint/no-unused-vars": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/handlers/onCronjob/backgroundEvents/refreshConfirmationEstimation.test.tsx": {
"@typescript-eslint/explicit-function-return-type": {
"count": 2
Expand Down Expand Up @@ -327,6 +308,16 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/__mocks__/mockConnection.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 9
}
},
"packages/solana-wallet-snap/src/core/services/__mocks__/scanResponses.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/analytics/AnalyticsService.test.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
Expand Down Expand Up @@ -448,16 +439,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/mocks/mockConnection.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 9
}
},
"packages/solana-wallet-snap/src/core/services/mocks/scanResponses.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/name-resolution/NameResolutionService.test.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
Expand Down Expand Up @@ -698,9 +679,6 @@
},
"no-restricted-syntax": {
"count": 2
},
"no-unused-private-class-members": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/transactions/utils/isSpam.ts": {
Expand Down Expand Up @@ -1029,25 +1007,6 @@
"count": 2
}
},
"packages/solana-wallet-snap/src/core/utils/logMaybeSolanaError.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
},
"@typescript-eslint/no-explicit-any": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/utils/logger.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 3
},
"@typescript-eslint/no-explicit-any": {
"count": 10
},
"no-empty-function": {
"count": 5
}
},
"packages/solana-wallet-snap/src/core/utils/parseOrigin.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down
5 changes: 5 additions & 0 deletions packages/solana-wallet-snap/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# - production before submitting a PR
ENVIRONMENT=

# Log Level
# Possible Options: error, warn, info, debug, trace, silent
# Default: info
LOG_LEVEL=

# List of RPC URLs for each network.
# The first one in the list is the primary one, the others are fallbacks.
RPC_URL_MAINNET_LIST=
Expand Down
17 changes: 0 additions & 17 deletions packages/solana-wallet-snap/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { jest } from '@jest/globals';
import BigNumber from 'bignumber.js';
import dotenv from 'dotenv';

import logger from './src/core/utils/logger';

dotenv.config();

// Lowest precision we ever go for: MicroLamports represented in Sol amount
BigNumber.config({ EXPONENTIAL_AT: 16 });

// Mock the console methods
jest.spyOn(logger, 'log').mockImplementation(() => {
/* no-op */
});
jest.spyOn(logger, 'info').mockImplementation(() => {
/* no-op */
});
jest.spyOn(logger, 'warn').mockImplementation(() => {
/* no-op */
});
jest.spyOn(logger, 'error').mockImplementation(() => {
/* no-op */
});
1 change: 1 addition & 0 deletions packages/solana-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@metamask/key-tree": "^10.1.1",
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/snap-networks-utils": "^1.0.0",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
"@metamask/snaps-sdk": "^11.2.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/solana-wallet-snap/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable n/no-process-env */
/* eslint-disable import-x/no-nodejs-modules, no-restricted-globals -- Snap configuration executes in Node.js. */
import type { SnapConfig } from '@metamask/snaps-cli';
import * as dotenv from 'dotenv';
import { resolve } from 'path';
Expand All @@ -7,6 +7,7 @@ dotenv.config();

const environment = {
ENVIRONMENT: process.env.ENVIRONMENT ?? '',
LOG_LEVEL: process.env.LOG_LEVEL ?? '',
RPC_URL_MAINNET_LIST: process.env.RPC_URL_MAINNET_LIST ?? '',
RPC_URL_DEVNET_LIST: process.env.RPC_URL_DEVNET_LIST ?? '',
RPC_URL_TESTNET_LIST: process.env.RPC_URL_TESTNET_LIST ?? '',
Expand Down
2 changes: 1 addition & 1 deletion packages/solana-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "YaPEFBNuMbbASorQCj4MFJKRSlqOjSOqJoOGUB9ET2I=",
"shasum": "dlsGUfU2sircQb9+jdv2u74wqp3t/Zn82O0JrY2lHAw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Logger } from '@metamask/snap-networks-utils/logger';
import { assert } from '@metamask/utils';

import type { Serializable } from '../serialization/types';
import { createPrefixedLogger } from '../utils/logger';
import type { ILogger } from '../utils/logger';
import type { ICache } from './ICache';
import type { CacheEntry } from './types';

Expand All @@ -15,10 +14,10 @@ import type { CacheEntry } from './types';
export class InMemoryCache implements ICache<Serializable> {
readonly #cache: Map<string, CacheEntry> = new Map();

public readonly logger: ILogger;
public readonly logger: Logger;

constructor(logger: ILogger) {
this.logger = createPrefixedLogger(logger, '[💾 InMemoryCache]');
constructor(logger: Logger) {
this.logger = logger.withPrefix('[💾 InMemoryCache]');
}

#validateTtlOrThrow(ttlMilliseconds?: number): void {
Expand Down
7 changes: 4 additions & 3 deletions packages/solana-wallet-snap/src/core/caching/StateCache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Logger } from '@metamask/snap-networks-utils/logger';
import { assert } from '@metamask/utils';

import type { Serializable } from '../serialization/types';
import type { IStateManager } from '../services/state/IStateManager';
import type { ILogger } from '../utils/logger';
import defaultLogger from '../utils/logger';
import type { ICache } from './ICache';
import type { CacheEntry } from './types';

Expand Down Expand Up @@ -74,11 +75,11 @@ export class StateCache implements ICache<Serializable | undefined> {

public readonly prefix: CachePrefix;

public readonly logger: ILogger;
public readonly logger: Logger;

constructor(
state: IStateManager<StateValue>,
logger: ILogger = console,
logger: Logger = defaultLogger,
prefix: CachePrefix = '__cache__default',
) {
this.#state = state;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable jest/no-mocks-import -- Test fixtures are imported directly. */
import type { ICache } from '../../caching/ICache';
import { InMemoryCache } from '../../caching/InMemoryCache';
import type { Serializable } from '../../serialization/types';
import { mockLogger } from '../../services/__mocks__/logger';
import type { ConfigProvider } from '../../services/config';
import { mockLogger } from '../../services/mocks/logger';
import { trackError } from '../../utils/errors';
import { MOCK_NFT_METADATA_RESPONSE_MAPPED } from './mocks/mockNftMetadataResponseMapped';
import { MOCK_NFT_METADATA_RESPONSE_RAW } from './mocks/mockNftMetadataResponseRaw';
Expand Down Expand Up @@ -38,12 +39,7 @@ describe('NftApiClient', () => {
}),
} as unknown as ConfigProvider;

client = new NftApiClient(
mockConfigProvider,
mockCache,
mockFetch,
mockLogger,
);
client = new NftApiClient(mockConfigProvider, mockCache, mockFetch);
});

describe('constructor', () => {
Expand All @@ -61,13 +57,7 @@ describe('NftApiClient', () => {
} as unknown as ConfigProvider;

expect(
() =>
new NftApiClient(
invalidConfigProvider,
mockCache,
mockFetch,
mockLogger,
),
() => new NftApiClient(invalidConfigProvider, mockCache, mockFetch),
).toThrow('Invalid URL format');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type { Serializable } from '../../serialization/types';
import type { ConfigProvider } from '../../services/config';
import { buildUrl } from '../../utils/buildUrl';
import { trackError } from '../../utils/errors';
import type { ILogger } from '../../utils/logger';
import logger from '../../utils/logger';
import { UrlStruct } from '../../validation/structs';
import type {
Balance,
Expand All @@ -22,8 +20,6 @@ import type {
export class NftApiClient {
readonly #fetch: typeof globalThis.fetch;

readonly #logger: ILogger;

readonly #baseUrl: string;

readonly #cache: ICache<Serializable>;
Expand All @@ -37,14 +33,12 @@ export class NftApiClient {
configProvider: ConfigProvider,
_cache: ICache<Serializable>,
_fetch: typeof globalThis.fetch = globalThis.fetch,
_logger: ILogger = logger,
) {
const { baseUrl, cacheTtlsMilliseconds } = configProvider.get().nftApi;

assert(baseUrl, UrlStruct);

this.#fetch = _fetch;
this.#logger = _logger;
this.#baseUrl = baseUrl;
this.#cacheTtlsMilliseconds = cacheTtlsMilliseconds;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jest/no-mocks-import -- Test fixtures are imported directly. */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { CaipAssetType } from '@metamask/keyring-api';
import { cloneDeep } from 'lodash';
Expand All @@ -6,8 +7,8 @@ import type { ICache } from '../../caching/ICache';
import { InMemoryCache } from '../../caching/InMemoryCache';
import { KnownCaip19Id } from '../../constants/solana';
import type { Serializable } from '../../serialization/types';
import { mockLogger } from '../../services/__mocks__/logger';
import type { ConfigProvider } from '../../services/config';
import { mockLogger } from '../../services/mocks/logger';
import { MOCK_EXCHANGE_RATES } from '../../test/mocks/price-api/exchange-rates';
import { MOCK_HISTORICAL_PRICES } from './mocks/historical-prices';
import { MOCK_SPOT_PRICES } from './mocks/spot-prices';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */

import type { CaipAssetType } from '@metamask/keyring-api';
import type { Logger } from '@metamask/snap-networks-utils/logger';
import { array, assert } from '@metamask/superstruct';
import { CaipAssetTypeStruct } from '@metamask/utils';
import { mapKeys } from 'lodash';
Expand All @@ -10,7 +11,6 @@ import { useCache } from '../../caching/useCache';
import type { Serializable } from '../../serialization/types';
import type { ConfigProvider } from '../../services/config';
import { buildUrl } from '../../utils/buildUrl';
import type { ILogger } from '../../utils/logger';
import logger from '../../utils/logger';
import { UrlStruct } from '../../validation/structs';
import type {
Expand All @@ -31,7 +31,7 @@ import {
export class PriceApiClient {
readonly #fetch: typeof globalThis.fetch;

readonly #logger: ILogger;
readonly #logger: Logger;

readonly #baseUrl: string;

Expand All @@ -49,7 +49,7 @@ export class PriceApiClient {
configProvider: ConfigProvider,
_cache: ICache<Serializable>,
_fetch: typeof globalThis.fetch = globalThis.fetch,
_logger: ILogger = logger,
_logger: Logger = logger,
) {
const { baseUrl, chunkSize, cacheTtlsMilliseconds } =
configProvider.get().priceApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jest/no-mocks-import -- Test fixtures are imported directly. */
import { Network } from '../../constants/solana';
import { mockLogger } from '../../services/__mocks__/logger';
import type { ConfigProvider } from '../../services/config';
import { mockLogger } from '../../services/mocks/logger';
import { SecurityAlertsApiClient } from './SecurityAlertsApiClient';

describe('SecurityAlertsApiClient', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Logger } from '@metamask/snap-networks-utils/logger';
/* eslint-disable no-restricted-globals */
import bs58 from 'bs58';

import { Network } from '../../constants/solana';
import type { ConfigProvider } from '../../services/config';
import type { ILogger } from '../../utils/logger';
import logger from '../../utils/logger';
import type { SecurityAlertSimulationValidationResponse } from './types';

Expand All @@ -17,14 +17,14 @@ const SCOPE_TO_CHAIN: Record<Network, string> = {
export class SecurityAlertsApiClient {
readonly #fetch: typeof globalThis.fetch;

readonly #logger: ILogger;
readonly #logger: Logger;

readonly #baseUrl: string;

constructor(
configProvider: ConfigProvider,
_fetch: typeof globalThis.fetch = globalThis.fetch,
_logger: ILogger = logger,
_logger: Logger = logger,
) {
const { baseUrl } = configProvider.get().securityAlertsApi;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable jest/no-mocks-import -- Test fixtures are imported directly. */
import type { TokenCaipAssetType } from '../../constants/solana';
import { KnownCaip19Id, Network } from '../../constants/solana';
import { mockLogger } from '../../services/__mocks__/logger';
import type { ConfigProvider } from '../../services/config';
import { mockLogger } from '../../services/mocks/logger';
import { tokenAddressToCaip19 } from '../../utils/tokenAddressToCaip19';
import { TokenApiClient } from './TokenApiClient';

Expand Down
Loading