Skip to content

Commit 3fb761c

Browse files
authored
WCv2 Native (#93)
1 parent 67d8d64 commit 3fb761c

File tree

183 files changed

+51798
-3794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+51798
-3794
lines changed

Assets/Thirdweb/Core/Prefabs/ThirdwebManager.prefab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Transform:
2424
m_PrefabInstance: {fileID: 0}
2525
m_PrefabAsset: {fileID: 0}
2626
m_GameObject: {fileID: 4404896360829706407}
27+
serializedVersion: 2
2728
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
2829
m_LocalPosition: {x: 0, y: 0, z: 0}
2930
m_LocalScale: {x: 1, y: 1, z: 1}
3031
m_ConstrainProportionsScale: 0
3132
m_Children: []
3233
m_Father: {fileID: 0}
33-
m_RootOrder: 0
3434
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3535
--- !u!114 &4404896360829706404
3636
MonoBehaviour:
@@ -93,6 +93,7 @@ MonoBehaviour:
9393
rpcOverride:
9494
clientId:
9595
initializeOnAwake: 1
96+
showDebugLogs: 1
9697
appName:
9798
appDescription:
9899
appIcons: []

Assets/Thirdweb/Core/Prefabs/WalletProvider_WalletConnect.prefab

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ GameObject:
446446
serializedVersion: 6
447447
m_Component:
448448
- component: {fileID: 3202619366221042882}
449+
- component: {fileID: 1981285479387489953}
449450
m_Layer: 0
450451
m_Name: WalletProvider_WalletConnect
451452
m_TagString: Untagged
@@ -469,6 +470,21 @@ Transform:
469470
m_Father: {fileID: 0}
470471
m_RootOrder: 0
471472
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
473+
--- !u!114 &1981285479387489953
474+
MonoBehaviour:
475+
m_ObjectHideFlags: 0
476+
m_CorrespondingSourceObject: {fileID: 0}
477+
m_PrefabInstance: {fileID: 0}
478+
m_PrefabAsset: {fileID: 0}
479+
m_GameObject: {fileID: 3202619366221042887}
480+
m_Enabled: 1
481+
m_EditorHideFlags: 0
482+
m_Script: {fileID: 11500000, guid: 13586f7257ca83d49b023e59549c6a31, type: 3}
483+
m_Name:
484+
m_EditorClassIdentifier:
485+
WalletConnectCanvas: {fileID: 3040857394524813045}
486+
QRCodeImage: {fileID: 4173661967735120711}
487+
DeepLinkButton: {fileID: 1670754136118778672}
472488
--- !u!1 &8183618418573995823
473489
GameObject:
474490
m_ObjectHideFlags: 0

Assets/Thirdweb/Core/Scripts/ThirdwebInterceptor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public override async Task<object> InterceptSendRequestAsync<T>(Func<RpcRequest,
2323
{
2424
switch (_thirdwebWallet.GetProvider())
2525
{
26+
case WalletProvider.WalletConnect:
27+
return ThirdwebManager.Instance.SDK.session.CurrentChainData.chainId;
2628
case WalletProvider.Metamask:
2729
return new HexBigInteger((BigInteger)MetaMask.Unity.MetaMaskUnity.Instance.Wallet.ChainId).HexValue;
2830
default:
@@ -80,6 +82,8 @@ params object[] paramList
8082
{
8183
switch (_thirdwebWallet.GetProvider())
8284
{
85+
case WalletProvider.WalletConnect:
86+
return ThirdwebManager.Instance.SDK.session.CurrentChainData.chainId;
8387
case WalletProvider.Metamask:
8488
return new HexBigInteger((BigInteger)MetaMask.Unity.MetaMaskUnity.Instance.Wallet.ChainId).HexValue;
8589
default:

Assets/Thirdweb/Core/Scripts/ThirdwebSession.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ internal async Task<string> Connect(WalletConnection walletConnection)
5858
ActiveWallet = new ThirdwebLocalWallet();
5959
break;
6060
case WalletProvider.WalletConnect:
61-
throw new UnityException("WalletConnectV2 is currently only supported in WebGL Builds, please check again later!");
62-
// if (Options.wallet == null || string.IsNullOrEmpty(Options.wallet?.walletConnectProjectId))
63-
// throw new UnityException("Wallet connect project id is required for wallet connect connection method!");
64-
// ActiveWallet = new ThirdwebWalletConnect(Options.wallet?.walletConnectProjectId);
65-
// break;
61+
if (Options.wallet == null || string.IsNullOrEmpty(Options.wallet?.walletConnectProjectId))
62+
throw new UnityException("Wallet connect project id is required for wallet connect connection method!");
63+
ActiveWallet = new ThirdwebWalletConnect(Options.wallet?.walletConnectProjectId);
64+
break;
6665
case WalletProvider.MagicLink:
6766
if (Options.wallet == null || string.IsNullOrEmpty(Options.wallet?.magicLinkApiKey))
6867
throw new UnityException("Magic link api key is required for magic link connection method!");

Assets/Thirdweb/Plugins/BouncyCastle.meta renamed to Assets/Thirdweb/Core/Scripts/WalletConnect.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Scripts/WalletConnect/Nethereum.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Nethereum.JsonRpc.Client;
2+
using Nethereum.RPC.Accounts;
3+
using Nethereum.RPC.AccountSigning;
4+
using Nethereum.RPC.NonceServices;
5+
using Nethereum.RPC.TransactionManagers;
6+
7+
namespace Thirdweb.WalletConnect
8+
{
9+
public class WalletConnectAccount : IAccount
10+
{
11+
private readonly WalletConnect _wallet;
12+
private readonly IClient _client;
13+
14+
public string Address
15+
{
16+
get { return _wallet.Accounts[0]; }
17+
}
18+
19+
public ITransactionManager TransactionManager { get; }
20+
public INonceService NonceService { get; set; }
21+
public IAccountSigningService AccountSigningService { get; }
22+
23+
public IClient Client
24+
{
25+
get { return _client; }
26+
}
27+
28+
public WalletConnectAccount(WalletConnect wallet, IClient client)
29+
{
30+
_wallet = wallet;
31+
_client = client;
32+
TransactionManager = new WalletConnectTransactionManager(this);
33+
NonceService = new InMemoryNonceService(Address, client);
34+
AccountSigningService = new AccountSigningService(client);
35+
}
36+
}
37+
}

Assets/Thirdweb/Core/Scripts/WalletConnect/Nethereum/WalletConnectAccount.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Nethereum.JsonRpc.Client;
5+
using Nethereum.JsonRpc.Client.RpcMessages;
6+
7+
namespace Thirdweb.WalletConnect
8+
{
9+
public class WalletConnectClient : ClientBase
10+
{
11+
private WalletConnect _walletConnect;
12+
13+
public WalletConnectClient(WalletConnect walletConnect)
14+
{
15+
this._walletConnect = walletConnect;
16+
}
17+
18+
private static readonly Random rng = new Random();
19+
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
20+
21+
public static long GenerateRpcId()
22+
{
23+
var date = (long)((DateTime.UtcNow - UnixEpoch).TotalMilliseconds) * (10L * 10L * 10L);
24+
var extra = (long)Math.Floor(rng.NextDouble() * (10.0 * 10.0 * 10.0));
25+
return date + extra;
26+
}
27+
28+
protected override async Task<RpcResponseMessage> SendAsync(RpcRequestMessage message, string route = null)
29+
{
30+
message.Id = GenerateRpcId();
31+
return await _walletConnect.Request(message);
32+
}
33+
34+
protected override Task<RpcResponseMessage[]> SendAsync(RpcRequestMessage[] requests)
35+
{
36+
return Task.WhenAll(requests.Select(r => SendAsync(r)));
37+
}
38+
}
39+
}

Assets/Thirdweb/Core/Scripts/WalletConnect/Nethereum/WalletConnectClient.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Nethereum.Web3;
2+
using Thirdweb.WalletConnect;
3+
4+
namespace Thirdweb.WalletConnect
5+
{
6+
public static class WalletConnectNEthereumExtensions
7+
{
8+
public static Web3 CreateWeb3(this WalletConnect walletConnect)
9+
{
10+
var client = new WalletConnectClient(walletConnect);
11+
var account = new WalletConnectAccount(walletConnect, client);
12+
return new Web3(account, client);
13+
}
14+
}
15+
}

Assets/Thirdweb/Core/Scripts/WalletConnect/Nethereum/WalletConnectNethereumExtensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Thirdweb.WalletConnect
2+
{
3+
public class WalletConnectTransactionManager : Nethereum.RPC.TransactionManagers.TransactionManager
4+
{
5+
public WalletConnectTransactionManager(WalletConnectAccount account)
6+
: base(account.Client)
7+
{
8+
Account = account;
9+
}
10+
}
11+
}

Assets/Thirdweb/Core/Scripts/WalletConnect/Nethereum/WalletConnectTransactionManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)