Skip to content

Commit a871da4

Browse files
committed
Wallet.Disconnect - option to not end session when available
1 parent 486b6c2 commit a871da4

File tree

9 files changed

+26
-23
lines changed

9 files changed

+26
-23
lines changed

Assets/Thirdweb/Core/Scripts/ThirdwebSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ await Connect(
124124
return addy;
125125
}
126126

127-
internal async Task Disconnect()
127+
internal async Task Disconnect(bool endSession = true)
128128
{
129129
if (ActiveWallet != null)
130130
{
131-
await ActiveWallet.Disconnect();
131+
await ActiveWallet.Disconnect(endSession);
132132
}
133133
else
134134
{

Assets/Thirdweb/Core/Scripts/Wallet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public async Task<string> Connect(WalletConnection walletConnection)
4444
/// Disconnects the user's wallet.
4545
/// </summary>
4646
/// <returns>A task representing the disconnection process.</returns>
47-
public async Task Disconnect()
47+
public async Task Disconnect(bool endSession = false)
4848
{
4949
if (Utils.IsWebGLBuild())
5050
{
5151
await Bridge.Disconnect();
5252
}
5353
else
5454
{
55-
await ThirdwebManager.Instance.SDK.session.Disconnect();
55+
await ThirdwebManager.Instance.SDK.session.Disconnect(endSession);
5656
}
5757
}
5858

Assets/Thirdweb/Core/Scripts/Wallets/IThirdwebWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IThirdwebWallet
2121
/// <summary>
2222
/// Main Disconnect call - should fully disconnect from the wallet and reset any variables.
2323
/// </summary>
24-
Task Disconnect();
24+
Task Disconnect(bool endSession = true);
2525

2626
/// <summary>
2727
/// Get the local account if any, return null otherwise.

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebEmbeddedWallet.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public async Task<string> Connect(WalletConnection walletConnection, string rpc)
4141
return await GetAddress();
4242
}
4343

44-
public async Task Disconnect()
44+
public async Task Disconnect(bool endSession = true)
4545
{
46-
await _embeddedWallet.SignOutAsync();
46+
if (endSession)
47+
await _embeddedWallet.SignOutAsync();
4748
_account = null;
4849
_web3 = null;
4950
}

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebHyperplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task<string> Connect(WalletConnection walletConnection, string rpc)
2828
return _hyperPlay.Accounts[0];
2929
}
3030

31-
public Task Disconnect()
31+
public Task Disconnect(bool endSession = true)
3232
{
3333
_web3 = null;
3434
return Task.CompletedTask;

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebLocalWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Task<string> Connect(WalletConnection walletConnection, string rpc)
2727
return Task.FromResult(_account.Address);
2828
}
2929

30-
public Task Disconnect()
30+
public Task Disconnect(bool endSession = true)
3131
{
3232
_account = null;
3333
_web3 = null;

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebMetamask.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void UpdateConfig(string appName, string appUrl)
3030
this.appUrl = appUrl;
3131
}
3232
}
33-
33+
3434
private Web3 _web3;
3535
private readonly WalletProvider _provider;
3636
private readonly WalletProvider _signerProvider;
@@ -65,13 +65,13 @@ private void SetupMetaMask()
6565
var appName = ThirdwebManager.Instance.SDK.session.Options.wallet?.appName;
6666
var appUrl = ThirdwebManager.Instance.SDK.session.Options.wallet?.appUrl;
6767
config.UpdateConfig(appName, appUrl);
68-
68+
6969
MetaMaskUnity.Instance.Initialize(config);
7070
}
7171

72-
public Task Disconnect()
72+
public Task Disconnect(bool endSession = true)
7373
{
74-
MetaMaskUnity.Instance.Disconnect(true);
74+
MetaMaskUnity.Instance.Disconnect(endSession);
7575
_web3 = null;
7676
return Task.CompletedTask;
7777
}

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebSmartWallet.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ public async Task<string> Connect(WalletConnection walletConnection, string rpc)
3737
return await GetAddress();
3838
}
3939

40-
public Task Disconnect()
40+
public async Task Disconnect(bool endSession = true)
4141
{
4242
_web3 = null;
43-
_personalWallet.Disconnect();
44-
return Task.CompletedTask;
43+
await _personalWallet.Disconnect(endSession);
4544
}
4645

4746
public Account GetLocalAccount()

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebWalletConnect.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ public async Task<string> Connect(WalletConnection walletConnection, string rpc)
4545
return await GetAddress();
4646
}
4747

48-
public async Task Disconnect()
48+
public async Task Disconnect(bool endSession = true)
4949
{
50-
try
50+
if (endSession)
5151
{
52-
await WalletConnect.Instance.DisconnectAsync();
53-
}
54-
catch (Exception e)
55-
{
56-
Debug.Log("Error disconnecting sign client: " + e.Message);
52+
try
53+
{
54+
await WalletConnect.Instance.DisconnectAsync();
55+
}
56+
catch (Exception e)
57+
{
58+
ThirdwebDebug.LogWarning($"Error disconnecting WalletConnect: {e.Message}");
59+
}
5760
}
5861

5962
_web3 = null;

0 commit comments

Comments
 (0)