Skip to content

Commit

Permalink
Connect Wallet Prefab Callback Support (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper authored Feb 22, 2023
1 parent aa72ba3 commit dfb6a7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Assets/Thirdweb/Examples/Prefabs/Prefab_ConnectWallet.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 874d8401331ede14087e8d8d486ddda6, type: 3}
m_Sprite: {fileID: 21300000, guid: 4a851c149a30f1e4b8088ab52b81444d, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
Expand Down Expand Up @@ -2145,7 +2145,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 6d6088174bb906b49ad8428526ee337b, type: 3}
m_Sprite: {fileID: 21300000, guid: 97e254ea33741df4686d7097f9d1435b, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
Expand Down Expand Up @@ -2286,6 +2286,15 @@ MonoBehaviour:
m_EditorClassIdentifier:
supportedWallets: 010000000200000003000000
supportSwitchingNetwork: 1
OnConnectedCallback:
m_PersistentCalls:
m_Calls: []
OnDisconnectedCallback:
m_PersistentCalls:
m_Calls: []
OnSwitchNetworkCallback:
m_PersistentCalls:
m_Calls: []
connectButton: {fileID: 1335404547334051784}
connectDropdown: {fileID: 1335404547797609896}
walletButtons:
Expand Down
12 changes: 12 additions & 0 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using TMPro;
using UnityEngine.UI;
using UnityEngine.Events;

public enum Wallet
{
Expand Down Expand Up @@ -35,6 +36,11 @@ public class Prefab_ConnectWallet : MonoBehaviour
public List<Wallet> supportedWallets;
public bool supportSwitchingNetwork;

[Header("CUSTOM CALLBACKS")]
public UnityEvent OnConnectedCallback;
public UnityEvent OnDisconnectedCallback;
public UnityEvent OnSwitchNetworkCallback;

[Header("UI ELEMENTS (DO NOT EDIT)")]
// Connecting
public GameObject connectButton;
Expand Down Expand Up @@ -109,6 +115,8 @@ public async void OnConnect(Wallet _wallet)

wallet = _wallet;
OnConnected();
if (OnConnectedCallback != null)
OnConnectedCallback.Invoke();
print($"Connected successfully to: {address}");
}
catch (Exception e)
Expand Down Expand Up @@ -150,6 +158,8 @@ public async void OnDisconnect()
{
await ThirdwebManager.Instance.SDK.wallet.Disconnect();
OnDisconnected();
if (OnDisconnectedCallback != null)
OnDisconnectedCallback.Invoke();
print($"Disconnected successfully.");

}
Expand Down Expand Up @@ -178,6 +188,8 @@ public async void OnSwitchNetwork(Chain _chain)
ThirdwebManager.Instance.chain = _chain;
await ThirdwebManager.Instance.SDK.wallet.SwitchNetwork((int)_chain);
OnConnected();
if (OnSwitchNetworkCallback != null)
OnSwitchNetworkCallback.Invoke();
print($"Switched Network Successfully: {_chain}");

}
Expand Down

0 comments on commit dfb6a7e

Please sign in to comment.