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

feat: web wallet #47

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 4 additions & 7 deletions sample/Reown.AppKit.Unity/Assets/Scenes/AppKit Init.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 10
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
Expand Down Expand Up @@ -42,8 +42,8 @@ RenderSettings:
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
serializedVersion: 13
m_BakeOnSceneLoad: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
Expand All @@ -66,9 +66,6 @@ LightmapSettings:
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
Expand Down Expand Up @@ -327,7 +324,7 @@ GameObject:
m_Component:
- component: {fileID: 1245457781}
m_Layer: 0
m_Name: ----- Web3Modal
m_Name: ----- AppKit
m_TagString: EditorOnly
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down
60 changes: 58 additions & 2 deletions sample/Reown.AppKit.Unity/Assets/Scenes/Init Scene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 22426080, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMax.x
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22426080, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 22426080, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchorMin.y
Expand All @@ -215,6 +215,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22428984, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22428984, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22428984, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand All @@ -239,6 +247,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22455554, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22455554, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22455554, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand Down Expand Up @@ -343,6 +359,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22468896, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22468896, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22468896, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand All @@ -367,6 +391,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22488670, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22488670, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22488670, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand All @@ -391,6 +423,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22495692, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22495692, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 22495692, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand All @@ -415,6 +455,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224619367409363176, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224619367409363176, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224619367409363176, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand All @@ -439,6 +487,14 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224856348943071238, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224856348943071238, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224856348943071238, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
Expand Down
61 changes: 61 additions & 0 deletions sample/Reown.AppKit.Unity/Assets/Scripts/AppInit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Linq;
using IngameDebugConsole;
using mixpanel;
using Newtonsoft.Json;
using Reown.AppKit.Unity;
using Skibitsky.Unity;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand All @@ -22,6 +26,7 @@ private void Start()
private void InitDebugConsole()
{
#if UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS
Debug.developerConsoleVisible = false; // disable Unity console
DontDestroyOnLoad(gameObject);
_debugConsole.SetActive(true);
#endif
Expand All @@ -39,5 +44,61 @@ private void ConfigureMixpanel()
Mixpanel.Track(logString, props);
};
}

[ConsoleMethod("accounts", "Lists all connected accounts")]
public static async void Accounts()
{
var accounts = await AppKit.ConnectorController.GetAccountsAsync();

if (accounts == null || accounts.Length == 0)
{
Debug.Log("No accounts connected");
return;
}

foreach (var account in accounts)
{
Debug.Log(account.AccountId);
}
}

[ConsoleMethod("sessionProps", "Prints session properties")]
public static void SessionProps()
{
var walletConnect = AppKit.ConnectorController.ActiveConnector as WalletConnectConnector;
var addressProvider = walletConnect.SignClient.AddressProvider;
var sessionProperties = addressProvider.DefaultSession.SessionProperties;

if (sessionProperties == null)
{
Debug.Log("No session properties found");
return;
}

var json = JsonConvert.SerializeObject(sessionProperties, new JsonSerializerSettings
{
Formatting = Formatting.Indented
});
Debug.Log(json);
}

[ConsoleMethod("session", "Prints active session")]
public static void Session()
{
var walletConnect = AppKit.ConnectorController.ActiveConnector as WalletConnectConnector;
var session = walletConnect.SignClient.AddressProvider.DefaultSession;

if (session == null)
{
Debug.Log("No active session found");
return;
}

var json = JsonConvert.SerializeObject(session, new JsonSerializerSettings
{
Formatting = Formatting.Indented
});
Debug.Log(json);
}
}
}
52 changes: 34 additions & 18 deletions sample/Reown.AppKit.Unity/Assets/Scripts/AppKitInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#if !UNITY_WEBGL
using mixpanel;
using Sentry;
#endif

namespace Sample
Expand All @@ -21,20 +22,20 @@ private async void Start()
// Set up Reown logger to collect logs from AppKit
ReownLogger.Instance = new UnityLogger();

// The very basic configuration of SIWE
var siweConfig = new SiweConfig
{
GetMessageParams = () => new SiweMessageParams
{
Domain = "example.com",
Uri = "https://example.com/login"
},
SignOutOnChainChange = false
};

// Subscribe to SIWE events
siweConfig.SignInSuccess += _ => Debug.Log("[Dapp] SIWE Sign In Success!");
siweConfig.SignOutSuccess += () => Debug.Log("[Dapp] SIWE Sign Out Success!");
// // The very basic configuration of SIWE
// var siweConfig = new SiweConfig
// {
// GetMessageParams = () => new SiweMessageParams
// {
// Domain = "example.com",
// Uri = "https://example.com/login"
// },
// SignOutOnChainChange = false
// };
//
// // Subscribe to SIWE events
// siweConfig.SignInSuccess += _ => Debug.Log("[Dapp] SIWE Sign In Success!");
// siweConfig.SignOutSuccess += () => Debug.Log("[Dapp] SIWE Sign Out Success!");

// AppKit configuration
var appKitConfig = new AppKitConfig
Expand All @@ -52,11 +53,18 @@ private async void Start()
Native = "appkit-sample-unity://"
}
),
customWallets = GetCustomWallets(),
// customWallets = GetCustomWallets(),
// On mobile show 5 wallets on the Connect view (the first AppKit modal screen)
connectViewWalletsCountMobile = 5,
// connectViewWalletsCountMobile = 5,
supportedChains = new[]
{
ChainConstants.Chains.Optimism,
ChainConstants.Chains.Ethereum,
ChainConstants.Chains.Arbitrum,
ChainConstants.Chains.Base
}
// Assign the SIWE configuration created above. Can be null if SIWE is not used.
siweConfig = siweConfig
// siweConfig = siweConfig
};

Debug.Log("[AppKit Init] Initializing AppKit...");
Expand All @@ -66,9 +74,17 @@ await AppKit.InitializeAsync(
);

#if !UNITY_WEBGL
// The Mixpanel is used by the sample project to collect telemetry
// The Mixpanel are Sentry are used by the sample project to collect telemetry
var clientId = await AppKit.Instance.SignClient.CoreClient.Crypto.GetClientId();
Mixpanel.Identify(clientId);

SentrySdk.ConfigureScope(scope =>
{
scope.User = new SentryUser
{
Id = clientId
};
});
#endif

Debug.Log($"[AppKit Init] AppKit initialized. Loading menu scene...");
Expand Down
Loading
Loading