Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ethers with submodules #95

Merged
merged 2 commits into from
Sep 9, 2022
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
"build:link": "yarn build && cd dist && yarn link && rm -rf node_modules && cd .."
},
"dependencies": {
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@metamask/controllers": "^30.0.0",
"@types/lodash": "^4.14.176",
"bignumber.js": "^9.0.1",
"ethers": "^5.5.1",
"fast-json-patch": "^3.1.0",
"isomorphic-fetch": "^3.0.0",
"lodash": "^4.17.21"
Expand Down
34 changes: 17 additions & 17 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import { SmartTransaction, SmartTransactionStatuses } from './types';

const confirmExternalMock = jest.fn();

jest.mock('ethers', () => ({
ethers: {
providers: {
Web3Provider: class Web3Provider {
getBalance = () => ({ toHexString: () => '0x1000' });
jest.mock('@ethersproject/bytes', () => ({
hexlify: (str: string) => `0x${str}`,
}));

getTransactionReceipt = jest.fn(() => ({ blockNumber: '123' }));
jest.mock('@ethersproject/providers', () => ({
Web3Provider: class Web3Provider {
getBalance = () => ({ toHexString: () => '0x1000' });

getTransaction = jest.fn(() => ({
maxFeePerGas: { toHexString: () => '0x123' },
maxPriorityFeePerGas: { toHexString: () => '0x123' },
}));
getTransactionReceipt = jest.fn(() => ({ blockNumber: '123' }));

getBlock = jest.fn();
},
},
utils: {
hexlify: (str: string) => `0x${str}`,
},
BigNumber: class BigNumber {},
getTransaction = jest.fn(() => ({
maxFeePerGas: { toHexString: () => '0x123' },
maxPriorityFeePerGas: { toHexString: () => '0x123' },
}));

getBlock = jest.fn();
},
}));

jest.mock('@ethersproject/bignumber', () => ({
BigNumber: class BigNumber {},
}));

const addressFrom = '0x268392a24B6b093127E8581eAfbD1DA228bAdAe3';

const createUnsignedTransaction = () => {
Expand Down
12 changes: 7 additions & 5 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
util,
} from '@metamask/controllers';
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { BigNumber as ethersBigNumber } from '@ethersproject/bignumber';
import { Web3Provider } from '@ethersproject/providers';
import { hexlify } from '@ethersproject/bytes';
import mapValues from 'lodash/mapValues';
import cloneDeep from 'lodash/cloneDeep';
import {
Expand Down Expand Up @@ -132,7 +134,7 @@ export default class SmartTransactionsController extends BaseController<

this.getNonceLock = getNonceLock;
this.getNetwork = getNetwork;
this.ethersProvider = new ethers.providers.Web3Provider(provider);
this.ethersProvider = new Web3Provider(provider);
this.confirmExternalTransaction = confirmExternalTransaction;
this.trackMetaMetricsEvent = trackMetaMetricsEvent;

Expand All @@ -144,7 +146,7 @@ export default class SmartTransactionsController extends BaseController<
this.configure({ chainId });
this.initializeSmartTransactionsForChainId();
this.checkPoll(this.state);
this.ethersProvider = new ethers.providers.Web3Provider(provider);
this.ethersProvider = new Web3Provider(provider);
});

this.subscribe((currentState: any) => this.checkPoll(currentState));
Expand Down Expand Up @@ -366,7 +368,7 @@ export default class SmartTransactionsController extends BaseController<
);
const baseFeePerGas = blockData?.baseFeePerGas.toHexString();
const txReceipt = mapValues(transactionReceipt, (value) => {
if (value instanceof ethers.BigNumber) {
if (value instanceof ethersBigNumber) {
return value.toHexString();
}
return value;
Expand Down Expand Up @@ -566,7 +568,7 @@ export default class SmartTransactionsController extends BaseController<
console.error('ethers error', e);
}
const nonceLock = await this.getNonceLock(txParams?.from);
const nonce = ethers.utils.hexlify(nonceLock.nextNonce);
const nonce = hexlify(nonceLock.nextNonce);
if (txParams && !txParams?.nonce) {
txParams.nonce = nonce;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jsonDiffer from 'fast-json-patch';
import _ from 'lodash';
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { hexlify } from '@ethersproject/bytes';
import {
APIType,
SmartTransaction,
Expand Down Expand Up @@ -208,5 +208,5 @@ export const isSmartTransactionCancellable = (

export const incrementNonceInHex = (nonceInHex: string): string => {
const nonceInDec = new BigNumber(nonceInHex, 16).toString(10);
return ethers.utils.hexlify(Number(nonceInDec) + 1);
return hexlify(Number(nonceInDec) + 1);
};
Loading