Skip to content

Commit

Permalink
Fix build error in vite when connecting safe (thirdweb-dev#859)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Daniels <[email protected]>
  • Loading branch information
MananTank and jnsdls authored Apr 5, 2023
1 parent b75bcef commit 229a474
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 2,235 deletions.
6 changes: 6 additions & 0 deletions .changeset/heavy-dolls-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@thirdweb-dev/wallets": patch
"@thirdweb-dev/react": patch
---

Fix Error when connecting to Safe in Vite
20 changes: 10 additions & 10 deletions packages/wallets/src/evm/connectors/safe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import type { SafeConnectionArgs } from "./types";
import { ethers } from "ethers";
import type { Signer } from "ethers";
import { AbstractBrowserWallet } from "../../wallets/base";
import {
SafeService,
SafeEthersSigner,
} from "@safe-global/safe-ethers-adapters";
import safeCoreSdk from "@safe-global/safe-core-sdk";
import safeEthersLib from "@safe-global/safe-ethers-lib";

// excerpt from https://docs.gnosis-safe.io/backend/available-services
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
Expand Down Expand Up @@ -88,23 +94,17 @@ export class SafeConnector extends TWConnector<SafeConnectionArgs> {
throw new Error("Chain not supported");
}

const [safeEthersAdapters, safeCoreSdk, safeEthersLib] = await Promise.all([
import("@safe-global/safe-ethers-adapters"),
import("@safe-global/safe-core-sdk"),
import("@safe-global/safe-ethers-lib"),
]);

const ethAdapter = new safeEthersLib.default({
const ethAdapter = new safeEthersLib({
ethers,
signerOrProvider: signer,
});

const safe = await safeCoreSdk.default.create({
const safe = await safeCoreSdk.create({
ethAdapter: ethAdapter as any,
safeAddress,
});
const service = new safeEthersAdapters.SafeService(serverUrl);
const safeSigner = new safeEthersAdapters.SafeEthersSigner(
const service = new SafeService(serverUrl);
const safeSigner = new SafeEthersSigner(
safe as any,
service,
signer.provider,
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/src/evm/wallets/safe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConnectParams, TWConnector } from "../interfaces/tw-connector";
import { AbstractBrowserWallet, WalletOptions } from "./base";
import type { Chain } from "@thirdweb-dev/chains";
import { SafeConnectionArgs } from "../connectors/safe/types";
import type { SafeConnectionArgs } from "../connectors/safe/types";
import type { SafeConnector as SafeConnectorType } from "../connectors/safe";

export { SafeSupportedChainsSet } from "../connectors/safe";
Expand Down
Loading

0 comments on commit 229a474

Please sign in to comment.