Skip to content

Commit

Permalink
chore: migrate wallets and signers to node16
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Aug 13, 2024
1 parent f4c25ba commit e849c40
Show file tree
Hide file tree
Showing 167 changed files with 655 additions and 477 deletions.
70 changes: 37 additions & 33 deletions global-wallets-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@ export {};

declare global {
interface Window {
ethereum: any;
braveSolana: any;
BinanceChain: any;
clover: any;
clover_solana: any;
cosmostation: any;
exodus: any;
solana: any;
phantom: any;
xfi: any;
coinbaseWalletExtension: any;
coinbaseSolana: any;
coin98: any;
keplr: any;
isSafePal: any;
safepal: any;
safepalProvider: any;
trustwallet: any;
okxwallet: any;
starknet_argentX: any;
starknet_braavos: any;
tronLink: any;
kucoin: any;
leap: any;
frontier: any;
terraWallets: any;
enkrypt: any;
tally: any;
bitkeep: any;
mytonwallet: any;
offlineSigner: any;
tomo_evm: any;
solflare: any;
// Some dependencies can override global environments, so maybe we needed to make some changes to make them compatible.
// This should be optional to `provider-solfare` can be compiled. see: `@solflare-wallet/metamask-sdk/lib/cjs/types.d.ts(74,18)`
ethereum?: any;
braveSolana?: any;
BinanceChain?: any;
clover?: any;
clover_solana?: any;
cosmostation?: any;
exodus?: any;
solana?: any;
phantom?: any;
xfi?: any;
coinbaseWalletExtension?: any;
coinbaseSolana?: any;
coin98?: any;
keplr?: any;
isSafePal?: any;
safepal?: any;
safepalProvider?: any;
trustwallet?: any;
okxwallet?: any;
starknet_argentX?: any;
starknet_braavos?: any;
tronLink?: any;
kucoin?: any;
leap?: any;
frontier?: any;
// This is for Station provider, `@terra-money/wallet-controller` adds this property to window automatically.
// file: node_modules/@terra-money/wallet-controller/modules/extension-router/multiChannel.d.ts
// terraWallets: any;
enkrypt?: any;
tally?: any;
bitkeep?: any;
mytonwallet?: any;
offlineSigner?: any;
tomo_evm?: any;
solflare?: any;
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"i18n": "yarn i18n:extract && yarn i18n:compile",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"commitlint": "commitlint --edit"
"commitlint": "commitlint --edit",
"postinstall": "patch-package"
},
"dependencies": {
"husky": "^8.0.3",
Expand Down Expand Up @@ -100,6 +101,8 @@
"nx": "16.2.1",
"os-browserify": "^0.3.0",
"parcel": "^2.11.0",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.7.1",
"punycode": "^1.4.1",
"querystring-es3": "^0.2.1",
Expand Down
11 changes: 11 additions & 0 deletions patches/@solflare-wallet+sdk+1.4.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/node_modules/@solflare-wallet/sdk/package.json b/node_modules/@solflare-wallet/sdk/package.json
index 6d43e38..8fd0274 100644
--- a/node_modules/@solflare-wallet/sdk/package.json
+++ b/node_modules/@solflare-wallet/sdk/package.json
@@ -1,5 +1,6 @@
{
"name": "@solflare-wallet/sdk",
+ "type": "module",
"version": "1.4.2",
"description": "",
"repository": "https://github.com/solflare-wallet/solflare-sdk",
15 changes: 15 additions & 0 deletions patches/@walletconnect+modal+2.6.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/node_modules/@walletconnect/modal/dist/_types/src/client.d.ts b/node_modules/@walletconnect/modal/dist/_types/src/client.d.ts
index fc7c092..258e47f 100644
--- a/node_modules/@walletconnect/modal/dist/_types/src/client.d.ts
+++ b/node_modules/@walletconnect/modal/dist/_types/src/client.d.ts
@@ -9,8 +9,8 @@ export type WalletConnectModalConfig = ConfigCtrlState & ThemeCtrlState;
export declare class WalletConnectModal {
constructor(config: WalletConnectModalConfig);
private initUi;
- openModal: (options?: import("packages/modal-core/dist/_types/src/controllers/ModalCtrl").OpenOptions | undefined) => Promise<void>;
+ openModal: (options?: import("@walletconnect/modal-core/dist/_types/src/controllers/ModalCtrl").OpenOptions | undefined) => Promise<void>;
closeModal: () => void;
- subscribeModal: (callback: (newState: import("packages/modal-core/dist/_types/src/types/controllerTypes").ModalCtrlState) => void) => () => void;
+ subscribeModal: (callback: (newState: import("@walletconnect/modal-core/dist/_types/src/types/controllerTypes").ModalCtrlState) => void) => () => void;
setTheme: (theme: ThemeCtrlState) => void;
}
19 changes: 16 additions & 3 deletions scripts/build/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ async function run() {
{ name: 'path', type: String },
// It accepts a comma separated file paths. e.g. src/main.ts,src/net.ts
{ name: 'inputs', type: String },
// Comma separated list. https://esbuild.github.io/api/#external
{ name: 'external', type: String },
];
const { path, inputs } = commandLineArgs(optionDefinitions);
const { path, inputs, external } = commandLineArgs(optionDefinitions);

if (!path) {
throw new Error('You need to specify package name.');
}

const pkgPath = `${root}/${path}`;
const entryPoint = `${pkgPath}/src/index.ts`;
const packageName = packageNameWithoutScope(packageJson(path).name);

let entryPoints = [];
Expand All @@ -36,6 +37,18 @@ async function run() {
entryPoints = inputs.split(',').map((input) => `${pkgPath}/${input}`);
}

// read more: https://esbuild.github.io/api/#packages
let externalPackages = {};
if (!external) {
externalPackages = {
packages: 'external',
};
} else {
externalPackages = {
external: external.split(','),
};
}

console.log(`[build] Running for ${path}`);

const typeCheckingTask = $({
Expand All @@ -50,10 +63,10 @@ async function run() {
sourcemap: true,
platform: 'node',
format: 'esm',
packages: 'external',
outdir: `${pkgPath}/dist`,
entryPoints: entryPoints,
metafile: true,
...externalPackages,
});
const result = await Promise.all([typeCheckingTask, esbuildTask]);
console.log(`[build] ${path} built successfully.`);
Expand Down
3 changes: 2 additions & 1 deletion signers/signer-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore",
"postinstall": "patch-package"
},
"dependencies": {
"@cosmjs/launchpad": "^0.27.1",
Expand Down
12 changes: 12 additions & 0 deletions signers/signer-cosmos/patches/long+5.2.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/node_modules/long/umd/index.d.ts b/node_modules/long/umd/index.d.ts
index c623535..9722763 100644
--- a/node_modules/long/umd/index.d.ts
+++ b/node_modules/long/umd/index.d.ts
@@ -1,2 +1,7 @@
+// @ts-expect-error this library has a build issue which breaks `esnext` and `nodendex` module resolution.
+// Issues:
+// https://github.com/dcodeIO/long.js/issues/125
+// https://github.com/dcodeIO/long.js/issues/131
+// https://github.com/dcodeIO/long.js/issues/109
import Long from "../index.js";
export = Long;
4 changes: 2 additions & 2 deletions signers/signer-cosmos/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DefaultCosmosSigner } from './signer';
export { executeCosmosTransaction, getsignedTx } from './helpers';
export { DefaultCosmosSigner } from './signer.js';
export { executeCosmosTransaction, getsignedTx } from './helpers.js';
11 changes: 7 additions & 4 deletions signers/signer-cosmos/src/signer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GenericSigner, CosmosTransaction } from 'rango-types';
import { executeCosmosTransaction } from './helpers';
import { Keplr } from '@keplr-wallet/types';
import type { Keplr } from '@keplr-wallet/types';
import type { CosmosTransaction, GenericSigner } from 'rango-types';

import { executeCosmosTransaction } from './helpers.js';

type CosmosExternalProvider = Keplr;

Expand All @@ -16,7 +17,9 @@ export class DefaultCosmosSigner implements GenericSigner<CosmosTransaction> {
address: string,
chainId: string | null
): Promise<string> {
if (!chainId) throw Error('ChainId is required');
if (!chainId) {
throw Error('ChainId is required');
}
const { signature } = await this.provider.signArbitrary(
chainId,
address,
Expand Down
6 changes: 2 additions & 4 deletions signers/signer-cosmos/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"extends": "../../tsconfig.lib.json",
"extends": "../../tsconfig.libnext.json",
"include": ["src", "types"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "./src",
"lib": ["dom", "esnext"],
// match output dir to input dir. e.g. dist/index instead of dist/src/index
"allowSyntheticDefaultImports": true
"lib": ["dom", "esnext"]
}
}
2 changes: 1 addition & 1 deletion signers/signer-evm/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SignerErrorCode,
} from 'rango-types';

import { MetamaskErrorCodes, RPCErrorCode, RPCErrorMessage } from './types';
import { MetamaskErrorCodes, RPCErrorCode, RPCErrorMessage } from './types.js';

export const cleanEvmError = (error: any): SignerErrorType => {
if (!error) {
Expand Down
4 changes: 2 additions & 2 deletions signers/signer-evm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DefaultEvmSigner } from './signer';
export { waitMs, cleanEvmError } from './helper';
export { DefaultEvmSigner } from './signer.js';
export { waitMs, cleanEvmError } from './helper.js';
6 changes: 3 additions & 3 deletions signers/signer-evm/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
TransactionResponse,
} from '@ethersproject/abstract-provider';
import type { GenericSigner } from 'rango-types';
import type { EvmTransaction } from 'rango-types/lib/api/main';
import type { EvmTransaction } from 'rango-types/mainApi';

import { providers } from 'ethers';
import {
Expand All @@ -12,8 +12,8 @@ import {
SignerErrorCode,
} from 'rango-types';

import { cleanEvmError, getTenderlyError, waitMs } from './helper';
import { RPCErrorCode } from './types';
import { cleanEvmError, getTenderlyError, waitMs } from './helper.js';
import { RPCErrorCode } from './types.js';

type ProviderType = ConstructorParameters<typeof providers.Web3Provider>[0];

Expand Down
10 changes: 6 additions & 4 deletions signers/signer-evm/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, beforeEach, it, expect } from 'vitest';
import { DefaultEvmSigner } from '../src/index';
import { MockEvmProvider } from '../../../test-utils/mock.evm.provider';
import { EVM_TX, address, privateKey } from './mock.data';
import { beforeEach, describe, expect, it } from 'vitest';

import { MockEvmProvider } from '../../../test-utils/mock.evm.provider.js';
import { DefaultEvmSigner } from '../src/index.js';

import { address, EVM_TX, privateKey } from './mock.data.js';

describe('Test EVM Signer', () => {
let provider: MockEvmProvider;
Expand Down
3 changes: 2 additions & 1 deletion signers/signer-evm/tests/mock.data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EvmTransaction } from 'rango-types/mainApi';

import { TransactionType } from 'rango-types';
import { EvmTransaction } from 'rango-types/lib/api/main';

export const address = '0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff';
export const privateKey =
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-evm/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"extends": "../../tsconfig.lib.json",
"extends": "../../tsconfig.libnext.json",
"include": ["src", "types"],
"compilerOptions": {
"outDir": "dist",
Expand Down
8 changes: 4 additions & 4 deletions signers/signer-solana/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { DefaultSolanaSigner } from './signer';
export { DefaultSolanaSigner } from './signer.js';
export {
executeSolanaTransaction,
generalSolanaTransactionExecutor,
prepareTransaction,
getSolanaConnection,
simulateTransaction,
} from './utils';
export type { SolanaWeb3Signer } from './utils';
export { setSolanaSignerConfig } from './config';
} from './utils/index.js';
export type { SolanaWeb3Signer } from './utils/index.js';
export { setSolanaSignerConfig } from './config.js';
4 changes: 2 additions & 2 deletions signers/signer-solana/src/signer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { SolanaExternalProvider } from './utils/types';
import type { SolanaExternalProvider } from './utils/types.js';
import type { GenericSigner, SolanaTransaction } from 'rango-types';

import { SignerError, SignerErrorCode } from 'rango-types';

import { executeSolanaTransaction } from './utils/main';
import { executeSolanaTransaction } from './utils/main.js';

export class DefaultSolanaSigner implements GenericSigner<SolanaTransaction> {
private provider: SolanaExternalProvider;
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-solana/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection } from '@solana/web3.js';

import { getSolanaSignerConfig } from '../config';
import { getSolanaSignerConfig } from '../config.js';

const IS_DEV = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
const SOLANA_RPC_URL = !IS_DEV
Expand Down
10 changes: 5 additions & 5 deletions signers/signer-solana/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export type { SolanaWeb3Signer, SolanaExternalProvider } from './types';
export type { SolanaWeb3Signer, SolanaExternalProvider } from './types.js';
export {
executeSolanaTransaction,
generalSolanaTransactionExecutor,
} from './main';
export { prepareTransaction } from './prepare';
export { getSolanaConnection } from './helpers';
export { simulateTransaction } from './simulate';
} from './main.js';
export { prepareTransaction } from './prepare.js';
export { getSolanaConnection } from './helpers.js';
export { simulateTransaction } from './simulate.js';
10 changes: 5 additions & 5 deletions signers/signer-solana/src/utils/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SolanaExternalProvider, SolanaWeb3Signer } from './types';
import type { SolanaExternalProvider, SolanaWeb3Signer } from './types.js';
import type { SolanaTransaction } from 'rango-types';

import { SignerError, SignerErrorCode } from 'rango-types';

import { getSolanaConnection } from './helpers';
import { prepareTransaction } from './prepare';
import { transactionSenderAndConfirmationWaiter } from './send';
import { simulateTransaction } from './simulate';
import { getSolanaConnection } from './helpers.js';
import { prepareTransaction } from './prepare.js';
import { transactionSenderAndConfirmationWaiter } from './send.js';
import { simulateTransaction } from './simulate.js';

/*
* https://docs.phantom.app/integrating/sending-a-transaction
Expand Down
4 changes: 2 additions & 2 deletions signers/signer-solana/src/utils/send.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {
TransactionSenderAndConfirmationWaiterArgs,
TransactionSenderAndConfirmationWaiterResponse,
} from './types';
} from './types.js';

import { TransactionExpiredBlockheightExceededError } from '@solana/web3.js';
import promiseRetry from 'promise-retry';

import { wait } from './helpers';
import { wait } from './helpers.js';

const SEND_OPTIONS = {
skipPreflight: true,
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-solana/src/utils/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Transaction, VersionedTransaction } from '@solana/web3.js';

import { SignerError, SignerErrorCode } from 'rango-types';

import { getSolanaConnection } from './helpers';
import { getSolanaConnection } from './helpers.js';

const INSUFFICIENT_FUNDS_ERROR_CODE = 1;
const SLIPPAGE_ERROR_CODE = 6001;
Expand Down
Loading

0 comments on commit e849c40

Please sign in to comment.