Skip to content

[Unity] SW Account Override Support #1986

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

Merged
merged 2 commits into from
Nov 21, 2023
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
5 changes: 5 additions & 0 deletions .changeset/gold-parents-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/unity-js-bridge": patch
---

[Unity] Support Smart Wallet Account Override
9 changes: 8 additions & 1 deletion packages/unity-js-bridge/src/thirdweb-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface TWBridge {
email?: string,
personalWallet?: PossibleWallet,
authOptions?: string,
smartWalletAccountOverride?: string,
) => Promise<string>;
disconnect: () => Promise<void>;
switchNetwork: (chainId: string) => Promise<void>;
Expand Down Expand Up @@ -256,6 +257,7 @@ class ThirdwebBridge implements TWBridge {
email?: string,
personalWallet: PossibleWallet = "localWallet",
authOptions?: string,
smartWalletAccountOverride?: string,
) {
if (!this.activeSDK) {
throw new Error("SDK not initialized");
Expand Down Expand Up @@ -346,7 +348,7 @@ class ThirdwebBridge implements TWBridge {
);
if (this.activeWallet) {
// Pass EOA and reconnect to initialize smart wallet
await this.initializeSmartWallet(smartWallet, this.activeWallet);
await this.initializeSmartWallet(smartWallet, this.activeWallet, smartWalletAccountOverride);
} else {
// If EOA wallet is not connected, throw error
throw new Error(
Expand Down Expand Up @@ -623,11 +625,16 @@ class ThirdwebBridge implements TWBridge {
public async initializeSmartWallet(
sw: SmartWallet,
personalWallet: AbstractClientWallet,
accountAddress?: string,
) {
if(accountAddress) {
console.debug("Initializing smart wallet with account address override:", accountAddress);
}
const personalWalletAddress = await personalWallet.getAddress();
console.debug("Personal wallet address:", personalWalletAddress);
await sw.connect({
personalWallet,
accountAddress: accountAddress,
});
if (sw.listenerCount("disconnect") === 1) {
sw.on("disconnect", () => {
Expand Down