Skip to content

Commit

Permalink
SIWE for EOA wallets (#136)
Browse files Browse the repository at this point in the history
* SIWE button

* Simplify LoginModal setup. Update login ui to match web and launcher

* Lowercase separator text

* Update external wallet logic (WIP)

* Update Thirdweb sdk to 5.11.1

* Prompt user to switch to correct network before using wallet connect

* Only init WalletConnect after clicking Wallet button

* Add config option to toggle wallet login

* Use ecosystem wallets for external wallets flow

* Improve UX on WalletConnect flow

* Avoid unnecessary transition modal animation on wallet connect

* Remove hardcoded chain id

---------

Co-authored-by: lefarchi <[email protected]>
  • Loading branch information
WyattMufson and lefarchi authored Dec 3, 2024
1 parent cb0728a commit 81744ef
Show file tree
Hide file tree
Showing 20 changed files with 1,455 additions and 3,092 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
# Visual Studio cache directory
.vs/

# IntelliJ IDEA cache directory
.idea/
*.iml
*.iml.meta

# Gradle cache directory
.gradle/

Expand Down
30 changes: 15 additions & 15 deletions Assets/Thirdweb/Plugins/Thirdweb.Plugins.asmdef
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "Thirdweb.Plugins",
"rootNamespace": "",
"references": [
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
{
"name": "Thirdweb.Plugins",
"rootNamespace": "",
"references": [
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
Binary file modified Assets/Thirdweb/Runtime/NET/Thirdweb.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Thirdweb/Runtime/Unity/ThirdwebManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public class ThirdwebManager : MonoBehaviour

public static ThirdwebManager Instance { get; private set; }

public static readonly string THIRDWEB_UNITY_SDK_VERSION = "5.10.0";
public static readonly string THIRDWEB_UNITY_SDK_VERSION = "5.11.1";

private bool _initialized;

Expand Down
65 changes: 37 additions & 28 deletions Assets/Thirdweb/Runtime/Unity/Wallets/Core/WalletConnectWallet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Nethereum.ABI.EIP712;
using WalletConnectSharp.Sign.Models;
Expand Down Expand Up @@ -60,6 +59,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
}

CreateNewSession(eip155ChainsSupported);
WalletConnectModal.ModalClosed += OnModalClosed;

while (!WalletConnect.Instance.IsConnected && _exception == null)
{
Expand All @@ -68,6 +68,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI

if (_exception != null)
{
WalletConnectModal.ModalClosed -= OnModalClosed;
throw _exception;
}
else
Expand All @@ -93,7 +94,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
return new WalletConnectWallet(client);
}

public async Task EnsureCorrectNetwork(BigInteger chainId)
public async Task SwitchNetwork(BigInteger chainId)
{
var currentChainId = WalletConnect.Instance.ActiveChainId;
if (currentChainId == $"eip155:{chainId}")
Expand Down Expand Up @@ -125,6 +126,12 @@ public async Task EnsureCorrectNetwork(BigInteger chainId)
await WalletConnect.Instance.SignClient.AddressProvider.SetDefaultChainIdAsync($"eip155:{chainId}");
}

[Obsolete("Use SwitchNetwork instead.")]
public Task EnsureCorrectNetwork(BigInteger chainId)
{
return SwitchNetwork(chainId);
}

#region IThirdwebWallet

public Task<string> GetAddress()
Expand Down Expand Up @@ -254,6 +261,26 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
throw new NotImplementedException();
}

public Task<List<LinkedAccount>> LinkAccount(
IThirdwebWallet walletToLink,
string otp = null,
bool? isMobile = null,
Action<string> browserOpenAction = null,
string mobileRedirectScheme = "thirdweb://",
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
)
{
throw new InvalidOperationException("LinkAccount is not supported by external wallets.");
}

public Task<List<LinkedAccount>> GetLinkedAccounts()
{
throw new InvalidOperationException("GetLinkedAccounts is not supported by external wallets.");
}

#endregion

#region UI
Expand All @@ -276,20 +303,22 @@ protected static void CreateNewSession(string[] supportedChains)
};

var connectOptions = new ConnectOptions { OptionalNamespaces = optionalNamespaces, };

// Open modal
WalletConnectModal.Open(new WalletConnectModalOptions { ConnectOptions = connectOptions, IncludedWalletIds = _includedWalletIds });
WalletConnectModal.ModalClosed += (sender, e) =>
{
_exception = new Exception("WalletConnect modal was closed.");
};
}
catch (Exception e)
{
_exception = e;
}
}

protected static void OnModalClosed(object sender, EventArgs e)
{
if (!WalletConnect.Instance.IsConnected)
{
_exception = new Exception("WalletConnect modal was closed.");
}
}

#endregion

private void SessionRequestDeeplink()
Expand All @@ -299,25 +328,5 @@ private void SessionRequestDeeplink()
WalletConnect.Instance.Linker.OpenSessionRequestDeepLinkAfterMessageFromSession(activeSessionTopic);
#endif
}

public Task<List<LinkedAccount>> LinkAccount(
IThirdwebWallet walletToLink,
string otp = null,
bool? isMobile = null,
Action<string> browserOpenAction = null,
string mobileRedirectScheme = "thirdweb://",
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
)
{
throw new InvalidOperationException("LinkAccount is not supported by external wallets.");
}

public Task<List<LinkedAccount>> GetLinkedAccounts()
{
throw new InvalidOperationException("GetLinkedAccounts is not supported by external wallets.");
}
}
}
182 changes: 182 additions & 0 deletions Assets/Treasure/Example/Scenes/TDKHarness.unity
Original file line number Diff line number Diff line change
Expand Up @@ -8059,6 +8059,187 @@ MonoBehaviour:
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1001 &1990817969
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 927399162371239047, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2170822260322079042, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517481203502194, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517481203502194, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517481203502194, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517481203502194, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517481203502194, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482676143954, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482676143954, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482676143954, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482676143954, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482750477834, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482750477834, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482750477834, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3645517482750477834, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5769675580277394246, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: <InitializeOnAwake>k__BackingField
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5852007486238492023, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_Name
value: WalletConnectModal
objectReference: {fileID: 0}
- target: {fileID: 6065279674905622718, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6065279674905622718, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6065279674905622718, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6065279674905622718, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996237597454, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7774600996784407750, guid: 6393a0b7364627248830caa747134c99, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6393a0b7364627248830caa747134c99, type: 3}
--- !u!1 &2002834091
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -8719,3 +8900,4 @@ SceneRoots:
- {fileID: 1405157655}
- {fileID: 1337487402}
- {fileID: 1834038110}
- {fileID: 1990817969}
Loading

0 comments on commit 81744ef

Please sign in to comment.