-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectUI.cs
99 lines (92 loc) · 3.19 KB
/
ConnectUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using UnityEngine;
using Treasure;
using System.Collections.Generic;
using UnityEngine.UI;
public class ConnectUI : MonoBehaviour
{
[SerializeField] private DropDownPopUp dropdownDialogPrefab;
[SerializeField] private Button webGLExternalReconnectButton;
private List<string> _chainIdentifiers = new List<string> {
"arbitrum",
"arbitrum-sepolia",
"ethereum",
"sepolia",
"treasure",
"treasure-ruby",
"treasure-topaz"
};
private List<ChainId> _chainIds = new List<ChainId> {
ChainId.Arbitrum,
ChainId.ArbitrumSepolia,
ChainId.Mainnet,
ChainId.Sepolia,
ChainId.Treasure,
ChainId.TreasureRuby,
ChainId.TreasureTopaz
};
void Start()
{
if (TDKWebConnectInterface.IsActive())
{
webGLExternalReconnectButton.interactable = true;
if (TDKWebConnectInterface.BrowserHasActiveWalletConnection())
{
TDKLogger.LogInfo("ConnectUI: an active wallet connection has been detected in the browser");
}
else
{
TDKWebConnectInterface.BrowserWalletConnectedAction += () =>
{
if (TDKWebConnectInterface.BrowserHasActiveWalletConnection())
{
TDKLogger.LogInfo("ConnectUI: an active wallet connection has been detected in the browser");
}
};
}
}
else
{
webGLExternalReconnectButton.interactable = false;
}
}
public void OnConnectWalletBtn()
{
TDK.Connect.ShowConnectModal();
}
public void OnSetChainBtn()
{
Instantiate(dropdownDialogPrefab, transform.GetComponentInParent<Canvas>().transform)
.Show("Set Chain", "Select an option from one of the chains below:", OnChainDropdownSubmit, _chainIdentifiers);
}
public async void OnChainDropdownSubmit(int value)
{
await TDK.Connect.SetChainId(_chainIds[value]);
}
public async void OnWebGLExternalReconnectBtn()
{
var thirdwebService = TDKServiceLocator.GetService<TDKThirdwebService>();
var isWalletConnected = await thirdwebService.IsWalletConnected();
if (isWalletConnected)
{
TDKLogger.LogInfo("Wallet already connected, aborting.");
return;
}
if (TDKWebConnectInterface.BrowserHasActiveWalletConnection())
{
TDKLogger.LogInfo("Requesting auth data from the browser...");
TDKWebConnectInterface.AttemptReconnect();
}
else
{
var browserConnectionState = TDKWebConnectInterface.GetBrowserConnectionState();
if (browserConnectionState == TDKWebConnectInterface.BrowserConnectionState.Disconnected)
{
TDKLogger.LogInfo("Invalid request: no active connection found in the browser");
}
else if (browserConnectionState == TDKWebConnectInterface.BrowserConnectionState.NewConnection)
{
TDKLogger.LogInfo("Invalid request: a new connection attempt was started");
}
}
}
}