1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 09:23:21 +01:00

feature: convert shared/modules/contract-utils.test.js to typescript (#17435)

This commit is contained in:
Danica Shen 2023-01-26 17:59:49 +00:00 committed by GitHub
parent ab329e5186
commit 787add7c70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 12 deletions

View File

@ -1,12 +0,0 @@
export const readAddressAsContract = async (ethQuery, address) => {
let contractCode;
try {
contractCode = await ethQuery.getCode(address);
} catch (e) {
contractCode = null;
}
const isContractAddress =
contractCode && contractCode !== '0x' && contractCode !== '0x0';
return { contractCode, isContractAddress };
};

View File

@ -0,0 +1,23 @@
type contract = {
contractCode: string | null;
isContractAddress: boolean;
};
export const readAddressAsContract = async (
ethQuery: {
getCode: (address: string) => string;
},
address: string,
): Promise<contract> => {
let contractCode;
try {
contractCode = await ethQuery.getCode(address);
} catch (e) {
contractCode = null;
}
const isContractAddress = contractCode
? contractCode !== '0x' && contractCode !== '0x0'
: false;
return { contractCode, isContractAddress };
};