Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgl wallet connect #152

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ sysinfo.txt
*.aab
*.unitypackage
*.app
webglbuild/

# Crashlytics generated file
crashlytics-build.properties
Expand Down
Binary file modified Assets/Thirdweb/Runtime/NET/Thirdweb.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public abstract class ThirdwebManagerBase : MonoBehaviour

public static ThirdwebManagerBase Instance { get; protected set; }

public static readonly string THIRDWEB_UNITY_SDK_VERSION = "5.17.2";
public static readonly string THIRDWEB_UNITY_SDK_VERSION = "5.18.2";

protected const string THIRDWEB_AUTO_CONNECT_OPTIONS_KEY = "ThirdwebAutoConnectOptions";

Expand Down
214 changes: 214 additions & 0 deletions Assets/Treasure/Example/Scenes/TDKHarness.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4741,6 +4741,139 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 843119459}
m_CullTransparentMesh: 0
--- !u!1 &920250282
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 920250283}
- component: {fileID: 920250286}
- component: {fileID: 920250285}
- component: {fileID: 920250284}
m_Layer: 5
m_Name: Btn_WebGLExternalReconnect
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &920250283
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 920250282}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1955608646}
m_Father: {fileID: 2119049937}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 267.5, y: -50}
m_SizeDelta: {x: 175, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &920250284
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 920250282}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 920250285}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 2119049941}
m_TargetAssemblyTypeName: ConnectUI, Assembly-CSharp
m_MethodName: OnWebGLExternalReconnectBtn
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 1
m_CallState: 2
--- !u!114 &920250285
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 920250282}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &920250286
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 920250282}
m_CullTransparentMesh: 0
--- !u!1 &948334912
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7910,6 +8043,85 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1932496921}
m_CullTransparentMesh: 0
--- !u!1 &1955608645
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1955608646}
- component: {fileID: 1955608648}
- component: {fileID: 1955608647}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1955608646
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1955608645}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 920250283}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1955608647
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1955608645}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 20
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: External reconnect (WebGL build)
--- !u!222 &1955608648
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1955608645}
m_CullTransparentMesh: 0
--- !u!1 &1969444263
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -8789,6 +9001,7 @@ RectTransform:
m_Children:
- {fileID: 1426026311}
- {fileID: 1354350607}
- {fileID: 920250283}
m_Father: {fileID: 1932496922}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
Expand Down Expand Up @@ -8841,6 +9054,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
dropdownDialogPrefab: {fileID: 3793558193243429674, guid: 5d64c9eae83be994eacd6780a6a8902d, type: 3}
webGLExternalReconnectButton: {fileID: 920250284}
--- !u!1001 &2785764880306549791
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
56 changes: 56 additions & 0 deletions Assets/Treasure/Example/Scripts/ConnectUI.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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",
Expand All @@ -25,6 +27,32 @@ public class ConnectUI : MonoBehaviour
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();
Expand All @@ -40,4 +68,32 @@ 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");
}
}
}
}
8 changes: 8 additions & 0 deletions Assets/Treasure/TDK/JSPlugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Treasure/TDK/JSPlugins/openConnectModal.jslib
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mergeInto(LibraryManager.library, {

WebGLNotifyReady: function () {
window.dispatchEvent(new CustomEvent("tdkReady"))
},

WebGLOpenConnectModal: function () {
window.dispatchEvent(new CustomEvent("tdkOpenConnectModal"))
},

WebGLOpenWalletConnectModal: function () {
window.dispatchEvent(new CustomEvent("tdkOpenWalletConnectModal"))
},

WebGLLogOut: function () {
window.dispatchEvent(new CustomEvent("tdkLogOut"))
},

WebGLRequestReconnect: function () {
window.dispatchEvent(new CustomEvent("tdkRequestReconnect"))
},

});
Loading