Skip to content

Commit

Permalink
refactor(common-scripts): simplify global provider check
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Jun 24, 2024
1 parent ac29338 commit 4b0b31f
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/common-scripts/src/omnilock-ethereum-displaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@ export async function signMessage(
digest: BytesLike,
provider?: Provider
): Promise<string> {
const internal: Provider = (() => {
if (provider) return provider;

/* c8 ignore start */
if (
typeof window !== "undefined" &&
"ethereum" in window &&
window.ethereum
) {
return window.ethereum as Provider;
}
const internal: Provider | undefined =
provider ?? (globalThis as { ethereum?: Provider }).ethereum;

if (!internal) {
throw new Error(
"No provider found, make sure you have installed MetaMask or the other EIP1193 compatible wallet"
);
/* c8 ignore stop */
})();
}

Check warning on line 27 in packages/common-scripts/src/omnilock-ethereum-displaying.ts

View check run for this annotation

Codecov / codecov/patch

packages/common-scripts/src/omnilock-ethereum-displaying.ts#L24-L27

Added lines #L24 - L27 were not covered by tests

const sig = await internal.request({
method: "personal_sign",
Expand Down

0 comments on commit 4b0b31f

Please sign in to comment.