Skip to content

Commit 7370866

Browse files
committed
Replace public-facing Serializeable Dictionary with Lists
Provides backwards-compatibility and better defaults that don't break the inspector values.
1 parent a682594 commit 7370866

9 files changed

+166
-149
lines changed

Assets/Thirdweb/Core/Scripts/ThirdwebSDK.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void FetchChainData()
181181
{
182182
chainId = BigInteger.Parse(currentNetwork.chainId).ToHex(false, true) ?? BigInteger.Parse(nativeSession.lastChainId.ToString()).ToHex(false, true),
183183
blockExplorerUrls = explorerUrls.ToArray(),
184-
chainName = currentNetwork.name ?? ThirdwebManager.Instance.supportedChainData[ThirdwebManager.Instance.chain].identifier,
184+
chainName = currentNetwork.name ?? ThirdwebManager.Instance.GetCurrentChainIdentifier(),
185185
iconUrls = new string[] { "ipfs://QmdwQDr6vmBtXmK2TmknkEuZNoaDqTasFdZdu3DRw8b2wt" },
186186
nativeCurrency = new NativeCurrency()
187187
{

Assets/Thirdweb/Examples/Prefabs/Prefab_ConnectWallet.prefab

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,21 @@ MonoBehaviour:
18981898
m_EditorClassIdentifier:
18991899
supportedWallets: 01000000020000000300000005000000
19001900
supportSwitchingNetwork: 1
1901-
supportedNetworks: 00000000010000000200000003000000
1901+
supportedNetworks:
1902+
- ethereum
1903+
- goerli
1904+
- polygon
1905+
- mumbai
1906+
- fantom
1907+
- fantom-testnet
1908+
- avalanche
1909+
- avalanche-fuji
1910+
- optimism
1911+
- optimism-goerli
1912+
- arbitrum
1913+
- arbitrum-goerli
1914+
- binance
1915+
- binance-testnet
19021916
OnConnectedCallback:
19031917
m_PersistentCalls:
19041918
m_Calls: []
@@ -1950,33 +1964,33 @@ MonoBehaviour:
19501964
networkDropdown: {fileID: 8325283099334609011}
19511965
networkButtonPrefab: {fileID: 6070093235809079241, guid: 814bcc588eda3914ab104d1c06491bc8, type: 3}
19521966
networkSprites:
1953-
- chain: 0
1967+
- chain: ethereum
19541968
sprite: {fileID: 21300000, guid: bf76ffa047029554199b8d79b2306f6d, type: 3}
1955-
- chain: 1
1969+
- chain: goerli
19561970
sprite: {fileID: 21300000, guid: bf76ffa047029554199b8d79b2306f6d, type: 3}
1957-
- chain: 2
1971+
- chain: polygon
19581972
sprite: {fileID: 21300000, guid: a4ac9bda74166b740bf880e481d41f55, type: 3}
1959-
- chain: 3
1973+
- chain: mumbai
19601974
sprite: {fileID: 21300000, guid: a4ac9bda74166b740bf880e481d41f55, type: 3}
1961-
- chain: 4
1975+
- chain: fantom
19621976
sprite: {fileID: 21300000, guid: 54be2d2440a31164f8679e1bd550abf9, type: 3}
1963-
- chain: 5
1977+
- chain: fantom-testnet
19641978
sprite: {fileID: 21300000, guid: 54be2d2440a31164f8679e1bd550abf9, type: 3}
1965-
- chain: 6
1979+
- chain: avalanche
19661980
sprite: {fileID: 21300000, guid: 3fe24f7fb0232e844988758a3ba03773, type: 3}
1967-
- chain: 7
1981+
- chain: avalanche-fuji
19681982
sprite: {fileID: 21300000, guid: 3fe24f7fb0232e844988758a3ba03773, type: 3}
1969-
- chain: 8
1983+
- chain: optimism
19701984
sprite: {fileID: 21300000, guid: b5be42ae0f66ca441beff78a90fe1680, type: 3}
1971-
- chain: 9
1985+
- chain: optimism-goerli
19721986
sprite: {fileID: 21300000, guid: b5be42ae0f66ca441beff78a90fe1680, type: 3}
1973-
- chain: 10
1987+
- chain: arbitrum
19741988
sprite: {fileID: 21300000, guid: 44b9a8a5b27749046b8fe998a084c7cc, type: 3}
1975-
- chain: 11
1989+
- chain: arbitrum-goerli
19761990
sprite: {fileID: 21300000, guid: 44b9a8a5b27749046b8fe998a084c7cc, type: 3}
1977-
- chain: 12
1991+
- chain: binance
19781992
sprite: {fileID: 21300000, guid: 427f73b440444d3428c9d1101f7c0646, type: 3}
1979-
- chain: 13
1993+
- chain: binance-testnet
19801994
sprite: {fileID: 21300000, guid: 427f73b440444d3428c9d1101f7c0646, type: 3}
19811995
--- !u!1 &1335404546759128316
19821996
GameObject:

Assets/Thirdweb/Examples/Prefabs/Prefab_ConnectWalletNative.prefab

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,33 +4191,33 @@ MonoBehaviour:
41914191
chainImage: {fileID: 6455197925238504093}
41924192
exportButton: {fileID: 1372153983861407458}
41934193
networkSprites:
4194-
- chain: 0
4194+
- chain: ethereum
41954195
sprite: {fileID: 21300000, guid: bf76ffa047029554199b8d79b2306f6d, type: 3}
4196-
- chain: 1
4196+
- chain: goerli
41974197
sprite: {fileID: 21300000, guid: bf76ffa047029554199b8d79b2306f6d, type: 3}
4198-
- chain: 2
4198+
- chain: polygon
41994199
sprite: {fileID: 21300000, guid: a4ac9bda74166b740bf880e481d41f55, type: 3}
4200-
- chain: 3
4200+
- chain: mumbai
42014201
sprite: {fileID: 21300000, guid: a4ac9bda74166b740bf880e481d41f55, type: 3}
4202-
- chain: 4
4202+
- chain: fantom
42034203
sprite: {fileID: 21300000, guid: 54be2d2440a31164f8679e1bd550abf9, type: 3}
4204-
- chain: 5
4204+
- chain: fantom-testnet
42054205
sprite: {fileID: 21300000, guid: 54be2d2440a31164f8679e1bd550abf9, type: 3}
4206-
- chain: 6
4206+
- chain: avalanche
42074207
sprite: {fileID: 21300000, guid: 3fe24f7fb0232e844988758a3ba03773, type: 3}
4208-
- chain: 7
4208+
- chain: avalanche-fuji
42094209
sprite: {fileID: 21300000, guid: 3fe24f7fb0232e844988758a3ba03773, type: 3}
4210-
- chain: 8
4210+
- chain: optimism
42114211
sprite: {fileID: 21300000, guid: b5be42ae0f66ca441beff78a90fe1680, type: 3}
4212-
- chain: 9
4212+
- chain: optimism-goerli
42134213
sprite: {fileID: 21300000, guid: b5be42ae0f66ca441beff78a90fe1680, type: 3}
4214-
- chain: 10
4214+
- chain: arbitrum
42154215
sprite: {fileID: 21300000, guid: 44b9a8a5b27749046b8fe998a084c7cc, type: 3}
4216-
- chain: 11
4216+
- chain: arbitrum-goerli
42174217
sprite: {fileID: 21300000, guid: 44b9a8a5b27749046b8fe998a084c7cc, type: 3}
4218-
- chain: 12
4218+
- chain: binance
42194219
sprite: {fileID: 21300000, guid: 427f73b440444d3428c9d1101f7c0646, type: 3}
4220-
- chain: 13
4220+
- chain: binance-testnet
42214221
sprite: {fileID: 21300000, guid: 427f73b440444d3428c9d1101f7c0646, type: 3}
42224222
--- !u!1 &8205008986028586947
42234223
GameObject:

Assets/Thirdweb/Examples/Prefabs/ThirdwebManager.prefab

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -44,75 +44,50 @@ MonoBehaviour:
4444
m_Script: {fileID: 11500000, guid: 56d9559a79e304f44b5ac4d726f1ee68, type: 3}
4545
m_Name:
4646
m_EditorClassIdentifier:
47-
chain: 1
47+
chain: goerli
4848
supportedChainData:
49-
reorderableList:
50-
canAdd: 1
51-
canRemove: 1
52-
draggable: 1
53-
expandable: 1
54-
multipleSelection: 1
55-
isExpanded: 0
56-
label:
57-
m_Text: Keys
58-
m_Image: {fileID: 0}
59-
m_Tooltip:
60-
headerHeight: 18
61-
footerHeight: 13
62-
slideEasing: 0.15
63-
verticalSpacing: 2
64-
showDefaultBackground: 1
65-
elementDisplayType: 0
66-
elementNameProperty:
67-
elementNameOverride:
68-
elementIcon: {fileID: 0}
69-
reqReferences: {fileID: 0}
70-
isExpanded: 0
71-
_keyValues: 000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d000000
72-
_keys: 000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d000000
73-
_values:
74-
- identifier: ethereum
75-
chainId: 1
76-
rpcOverride:
77-
- identifier: goerli
78-
chainId: 5
79-
rpcOverride:
80-
- identifier: polygon
81-
chainId: 137
82-
rpcOverride:
83-
- identifier: mumbai
84-
chainId: 80001
85-
rpcOverride:
86-
- identifier: fantom
87-
chainId: 250
88-
rpcOverride:
89-
- identifier: fantom-testnet
90-
chainId: 4002
91-
rpcOverride:
92-
- identifier: avalanche
93-
chainId: 43114
94-
rpcOverride:
95-
- identifier: avalanche-fuji
96-
chainId: 43113
97-
rpcOverride:
98-
- identifier: optimism
99-
chainId: 10
100-
rpcOverride:
101-
- identifier: optimism-goerli
102-
chainId: 420
103-
rpcOverride:
104-
- identifier: arbitrum
105-
chainId: 42161
106-
rpcOverride:
107-
- identifier: arbitrum-goerli
108-
chainId: 421613
109-
rpcOverride:
110-
- identifier: binance
111-
chainId: 56
112-
rpcOverride:
113-
- identifier: binance-testnet
114-
chainId: 97
115-
rpcOverride:
49+
- identifier: ethereum
50+
chainId: 1
51+
rpcOverride:
52+
- identifier: goerli
53+
chainId: 5
54+
rpcOverride:
55+
- identifier: polygon
56+
chainId: 137
57+
rpcOverride:
58+
- identifier: mumbai
59+
chainId: 80001
60+
rpcOverride:
61+
- identifier: fantom
62+
chainId: 250
63+
rpcOverride:
64+
- identifier: fantom-testnet
65+
chainId: 4002
66+
rpcOverride:
67+
- identifier: avalanche
68+
chainId: 43114
69+
rpcOverride:
70+
- identifier: avalanche-fuji
71+
chainId: 43113
72+
rpcOverride:
73+
- identifier: optimism
74+
chainId: 10
75+
rpcOverride:
76+
- identifier: optimism-goerli
77+
chainId: 420
78+
rpcOverride:
79+
- identifier: arbitrum
80+
chainId: 42161
81+
rpcOverride:
82+
- identifier: arbitrum-goerli
83+
chainId: 421613
84+
rpcOverride:
85+
- identifier: binance
86+
chainId: 56
87+
rpcOverride:
88+
- identifier: binance-testnet
89+
chainId: 97
90+
rpcOverride:
11691
storageIpfsGatewayUrl: https://gateway.ipfscdn.io/ipfs/
11792
relayerUrl:
11893
relayerForwarderAddress:

Assets/Thirdweb/Examples/Scenes/Scene_Prefabs.unity

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,6 @@ PrefabInstance:
603603
propertyPath: m_AnchorMax.y
604604
value: 0
605605
objectReference: {fileID: 0}
606-
- target: {fileID: 7216536800389251089, guid: 487e6840fccf4594ca24581d2b3e9d25, type: 3}
607-
propertyPath: m_AnchorMin.y
608-
value: 0
609-
objectReference: {fileID: 0}
610606
- target: {fileID: 7568917606152558407, guid: 487e6840fccf4594ca24581d2b3e9d25, type: 3}
611607
propertyPath: m_AnchorMax.y
612608
value: 0

Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWallet.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,32 @@ public struct WalletButton
2727
[Serializable]
2828
public struct NetworkSprite
2929
{
30-
public Chain chain;
30+
public string chain;
3131
public Sprite sprite;
3232
}
3333

3434
public class Prefab_ConnectWallet : MonoBehaviour
3535
{
3636
[Header("SETTINGS")]
37-
public List<Wallet> supportedWallets;
38-
public bool supportSwitchingNetwork;
39-
public List<Chain> supportedNetworks;
37+
public List<Wallet> supportedWallets = new List<Wallet>() { Wallet.MetaMask, Wallet.Injected, Wallet.CoinbaseWallet, Wallet.WalletConnect, Wallet.MagicAuth, Wallet.DeviceWallet };
38+
public bool supportSwitchingNetwork = true;
39+
public List<string> supportedNetworks = new List<string>()
40+
{
41+
"ethereum",
42+
"goerli",
43+
"polygon",
44+
"mumbai",
45+
"fantom",
46+
"fantom-testnet",
47+
"avalanche",
48+
"avalanche-fuji",
49+
"optimism",
50+
"optimism-goerli",
51+
"arbitrum",
52+
"arbitrum-goerli",
53+
"binance",
54+
"binance-testnet",
55+
};
4056

4157
[Header("CUSTOM CALLBACKS")]
4258
public UnityEvent OnConnectedCallback;
@@ -117,7 +133,7 @@ public async void OnConnect(Wallet _wallet)
117133
try
118134
{
119135
address = await ThirdwebManager.Instance.SDK.wallet.Connect(
120-
new WalletConnection() { provider = GetWalletProvider(_wallet), chainId = int.Parse(ThirdwebManager.Instance.supportedChainData[ThirdwebManager.Instance.chain].chainId), }
136+
new WalletConnection() { provider = GetWalletProvider(_wallet), chainId = int.Parse(ThirdwebManager.Instance.GetCurrentChainData().chainId), }
121137
);
122138

123139
wallet = _wallet;
@@ -148,8 +164,8 @@ async void OnConnected()
148164
}
149165
finally
150166
{
151-
Chain _chain = ThirdwebManager.Instance.chain;
152-
currentNetworkText.text = ThirdwebManager.Instance.supportedChainData[ThirdwebManager.Instance.chain].identifier;
167+
string _chain = ThirdwebManager.Instance.chain;
168+
currentNetworkText.text = ThirdwebManager.Instance.GetCurrentChainIdentifier();
153169
currentNetworkImage.sprite = networkSprites.Find(x => x.chain == _chain).sprite;
154170
connectButton.SetActive(false);
155171
connectedButton.SetActive(true);
@@ -191,12 +207,12 @@ void OnDisconnected()
191207

192208
// Switching Network
193209

194-
public async void OnSwitchNetwork(Chain _chain)
210+
public async void OnSwitchNetwork(string _chain)
195211
{
196212
try
197213
{
198214
ThirdwebManager.Instance.chain = _chain;
199-
await ThirdwebManager.Instance.SDK.wallet.SwitchNetwork(int.Parse(ThirdwebManager.Instance.supportedChainData[_chain].chainId));
215+
await ThirdwebManager.Instance.SDK.wallet.SwitchNetwork(int.Parse(ThirdwebManager.Instance.GetCurrentChainData().chainId));
200216
OnConnected();
201217
OnSwitchNetworkCallback?.Invoke();
202218
print($"Switched Network Successfully: {_chain}");
@@ -231,16 +247,16 @@ public void OnClickNetworkSwitch()
231247
foreach (Transform child in networkDropdown.transform)
232248
Destroy(child.gameObject);
233249

234-
foreach (Chain chain in Enum.GetValues(typeof(Chain)))
250+
foreach (ChainData chainData in ThirdwebManager.Instance.supportedChainData)
235251
{
236-
if (chain == ThirdwebManager.Instance.chain || !supportedNetworks.Contains(chain))
252+
if (chainData.identifier == ThirdwebManager.Instance.chain || !supportedNetworks.Contains(chainData.identifier))
237253
continue;
238254

239255
GameObject networkButton = Instantiate(networkButtonPrefab, networkDropdown.transform);
240256
networkButton.GetComponent<Button>().onClick.RemoveAllListeners();
241-
networkButton.GetComponent<Button>().onClick.AddListener(() => OnSwitchNetwork(chain));
242-
networkButton.transform.Find("Text_Network").GetComponent<TMP_Text>().text = ThirdwebManager.Instance.supportedChainData[chain].identifier;
243-
networkButton.transform.Find("Icon_Network").GetComponent<Image>().sprite = networkSprites.Find(x => x.chain == chain).sprite;
257+
networkButton.GetComponent<Button>().onClick.AddListener(() => OnSwitchNetwork(chainData.identifier));
258+
networkButton.transform.Find("Text_Network").GetComponent<TMP_Text>().text = chainData.identifier;
259+
networkButton.transform.Find("Icon_Network").GetComponent<Image>().sprite = networkSprites.Find(x => x.chain == chainData.identifier).sprite;
244260
}
245261
}
246262

Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWalletNative.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public struct WalletButtonNative
2626
[Serializable]
2727
public struct NetworkSpriteNative
2828
{
29-
public Chain chain;
29+
public string chain;
3030
public Sprite sprite;
3131
}
3232

3333
public class Prefab_ConnectWalletNative : MonoBehaviour
3434
{
3535
[Header("SETTINGS")]
36-
public List<WalletNative> supportedWallets;
36+
public List<WalletNative> supportedWallets = new List<WalletNative>() { WalletNative.DeviceWallet, WalletNative.WalletConnect };
3737

3838
[Header("CUSTOM CALLBACKS")]
3939
public UnityEvent OnConnectedCallback;
@@ -172,13 +172,13 @@ async void OnConnected()
172172
try
173173
{
174174
passwordPanel.SetActive(false);
175-
Chain _chain = ThirdwebManager.Instance.chain;
175+
string _chain = ThirdwebManager.Instance.chain;
176176
CurrencyValue nativeBalance = await ThirdwebManager.Instance.SDK.wallet.GetBalance();
177177
balanceText.text = $"{nativeBalance.value.ToEth()} {nativeBalance.symbol}";
178178
balanceText2.text = balanceText.text;
179179
walletAddressText.text = await Utils.GetENSName(address) ?? address.ShortenAddress();
180180
walletAddressText2.text = walletAddressText.text;
181-
currentNetworkText.text = ThirdwebManager.Instance.supportedChainData[ThirdwebManager.Instance.chain].identifier;
181+
currentNetworkText.text = ThirdwebManager.Instance.GetCurrentChainIdentifier();
182182
currentNetworkImage.sprite = networkSprites.Find(x => x.chain == _chain).sprite;
183183
connectButton.SetActive(false);
184184
connectedButton.SetActive(true);

0 commit comments

Comments
 (0)