Small refactorings; no semantic changes

This commit is contained in:
Willian Mitsuda 2021-12-13 15:11:34 -03:00
parent 0754c4f4bf
commit d5fa5dda36
1 changed files with 16 additions and 5 deletions

View File

@ -486,6 +486,9 @@ export const useAddressesWithCode = (
return results; return results;
}; };
// Error(string)
const ERROR_MESSAGE_SELECTOR = "0x08c379a0";
export const useTransactionError = ( export const useTransactionError = (
provider: JsonRpcProvider | undefined, provider: JsonRpcProvider | undefined,
txHash: string txHash: string
@ -505,14 +508,22 @@ export const useTransactionError = (
txHash, txHash,
])) as string; ])) as string;
// Filter hardcoded Error(string) selector because ethers don't let us // Empty or success
// construct it if (result === "0x") {
if (result.substr(0, 10) !== "0x08c379a0") {
return; return;
} }
const msg = defaultAbiCoder.decode(["string"], "0x" + result.substr(10)); // Filter hardcoded Error(string) selector because ethers don't let us
setErrorMsg(msg[0]); // construct it
const selector = result.substr(0, 10);
if (selector === ERROR_MESSAGE_SELECTOR) {
const msg = defaultAbiCoder.decode(
["string"],
"0x" + result.substr(10)
);
setErrorMsg(msg[0]);
return;
}
}; };
readCodes(); readCodes();
}, [provider, txHash]); }, [provider, txHash]);