From ae68f28aa95651e8b1400a116324770d8fa890e2 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Tue, 2 May 2023 18:19:08 +0200 Subject: [PATCH 1/7] Integrate XNFT wallet inside SolanaWalletAdapterWebGL - removes need of custom WebGLTemplates --- .../SolanaWalletAdapterWebGL.jslib | 30 +- Runtime/Plugins/xNFT.jslib | 58 ---- Runtime/Plugins/xNFT.jslib.meta | 32 --- .../Exporters/WebGLTemplatesExporter.cs | 50 ---- .../Exporters/WebGLTemplatesExporter.cs.meta | 11 - .../SolanaWalletAdapterWebGL.cs | 71 +++-- Runtime/codebase/Web3.cs | 10 - Runtime/codebase/WebGLTemplates.meta | 8 - Runtime/codebase/WebGLTemplates/xNFT.meta | 8 - .../codebase/WebGLTemplates/xNFT/index.html | 262 ------------------ .../WebGLTemplates/xNFT/index.html.meta | 7 - .../WebGLTemplates/xNFT/thumbnail.png | Bin 2184 -> 0 bytes .../WebGLTemplates/xNFT/thumbnail.png.meta | 7 - Runtime/codebase/XNFTWallet.cs | 128 --------- Runtime/codebase/XNFTWallet.cs.meta | 11 - .../Scripts/example/screens/LoginScreen.cs | 15 +- 16 files changed, 67 insertions(+), 641 deletions(-) delete mode 100644 Runtime/Plugins/xNFT.jslib delete mode 100644 Runtime/Plugins/xNFT.jslib.meta delete mode 100644 Runtime/codebase/Exporters/WebGLTemplatesExporter.cs delete mode 100644 Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta delete mode 100644 Runtime/codebase/WebGLTemplates.meta delete mode 100644 Runtime/codebase/WebGLTemplates/xNFT.meta delete mode 100644 Runtime/codebase/WebGLTemplates/xNFT/index.html delete mode 100644 Runtime/codebase/WebGLTemplates/xNFT/index.html.meta delete mode 100644 Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png delete mode 100644 Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta delete mode 100644 Runtime/codebase/XNFTWallet.cs delete mode 100644 Runtime/codebase/XNFTWallet.cs.meta diff --git a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib index ebea7e0b..52ce0793 100644 --- a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib +++ b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib @@ -4,14 +4,15 @@ if(window.walletAdapterLib == undefined){ console.log("Adding WalletAdapterLib") var script = document.createElement("script"); - script.src = "https://cdn.jsdelivr.net/gh/magicblock-labs/unity-js-wallet-adapter@main/dist/wallet-adapter-lib.js"; + script.src = "https://cdn.jsdelivr.net/gh/magicblock-labs/unity-js-wallet-adapter@xnft-helpers/dist/wallet-adapter-lib.js"; document.head.appendChild(script); script.onload = function() { console.log("WalletAdapterLib loaded"); - Module.dynCall_vi(callback); + const isXnft = Boolean("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined && window.xnft.solana.publicKey != undefined); + console.log("isXnft: " + isXnft); + Module.dynCall_vi(callback, isXnft); }; } - console.log(window.walletAdapterLib); }, ExternGetWallets: async function(callback) { try { @@ -27,7 +28,11 @@ ExternConnectWallet: async function (walletNamePtr, callback) { try { const walletName = UTF8ToString(walletNamePtr) - var pubKey = await window.walletAdapterLib.connectWallet(walletName); + if(walletName === 'XNFT'){ + var pubKey = window.xnft.solana.publicKey.toString(); + } else { + var pubKey = await window.walletAdapterLib.connectWallet(walletName); + } var bufferSize = lengthBytesUTF8(pubKey) + 1; var pubKeyPtr = _malloc(bufferSize); stringToUTF8(pubKey, pubKeyPtr, bufferSize); @@ -40,7 +45,12 @@ try { const walletName = UTF8ToString(walletNamePtr) var base64transaction = UTF8ToString(transactionPtr) - var signedTransaction = await window.walletAdapterLib.signTransaction(walletName, base64transaction); + if(walletName === 'XNFT'){ + const transaction = window.walletAdapterLib.getTransactionFromStr(base64transaction); + const signedTransaction = await window.xnft.solana.signTransaction(transaction); + } else { + const signedTransaction = await window.walletAdapterLib.signTransaction(walletName, base64transaction); + } var signature = signedTransaction.signature.toString('base64'); var bufferSize = lengthBytesUTF8(signature) + 1; var signaturePtr = _malloc(bufferSize); @@ -54,8 +64,14 @@ try { const walletName = UTF8ToString(walletNamePtr) var base64Message = UTF8ToString(messagePtr) - var signature = await window.walletAdapterLib.signMessage(walletName, base64Message); - var signatureStr = signature.toString('base64'); + if(walletName === 'XNFT'){ + const messageBytes = Uint8Array.from(atob(base64Message), (c) => c.charCodeAt(0)); + const signedMessage = await window.xnft.solana.signMessage(messageBytes); + var signatureStr = JSON.stringify(Array.from(signedMessage)); + } else { + var signature = await window.walletAdapterLib.signMessage(walletName, base64Message); + var signatureStr = signature.toString('base64'); + } var bufferSize = lengthBytesUTF8(signatureStr) + 1; var signaturePtr = _malloc(bufferSize); stringToUTF8(signatureStr, signaturePtr, bufferSize); diff --git a/Runtime/Plugins/xNFT.jslib b/Runtime/Plugins/xNFT.jslib deleted file mode 100644 index ec2f04bb..00000000 --- a/Runtime/Plugins/xNFT.jslib +++ /dev/null @@ -1,58 +0,0 @@ -mergeInto(LibraryManager.library, { - ExternConnectXNFT: async function (callback) { - if ("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined && window.xnft.solana.publicKey != undefined) { - try { - var pubKey = window.xnft.solana.publicKey.toString(); - var lenPubKey = lengthBytesUTF8(pubKey) + 1; - var strPtr = _malloc(lenPubKey); - stringToUTF8(pubKey, strPtr, lenPubKey); - Module.dynCall_vi(callback, strPtr); - } catch (err) { - console.error(err.message); - } - } else { - console.log("Not running in Backpack wallet"); - } - }, - - ExternSignTransactionXNFT: async function (transaction, callback) { - if ("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined) { - try { - const messageBase58 = UTF8ToString(transaction); - const message = solanaWeb3.Message.from(bs58.decode(messageBase58)); - const tx = solanaWeb3.Transaction.populate(message); - const signedTransaction = await window.xnft.solana.signTransaction(tx); - var sign = bs58.encode(signedTransaction.signature); - var lenSign = lengthBytesUTF8(sign) + 1; - var strPtr = _malloc(lenSign); - stringToUTF8(sign, strPtr, lenSign); - console.log(strPtr); - Module.dynCall_vi(callback, strPtr); - } catch (err) { - console.error(err.message); - } - } else { - console.error("Not running in Backpack wallet"); - } - }, - - ExternSignMessageXNFT: async function (message, callback) { - if ('xnft' in window && window.xnft != undefined && window.xnft.solana != undefined) { - try { - const messageBase64String = UTF8ToString(message); - const messageBytes = Uint8Array.from(atob(messageBase64String), (c) => c.charCodeAt(0)); - const signedMessage = await window.xnft.solana.signMessage(messageBytes); - console.log(signedMessage); - var sign = JSON.stringify(Array.from(signedMessage)); - var lenSign = lengthBytesUTF8(sign) + 1; - var strPtr = _malloc(lenSign); - stringToUTF8(sign, strPtr, lenSign); - Module.dynCall_vi(callback, strPtr); - } catch (err) { - console.error(err.message); - } - } else { - console.error("Not running in Backpack wallet"); - } - }, -}); diff --git a/Runtime/Plugins/xNFT.jslib.meta b/Runtime/Plugins/xNFT.jslib.meta deleted file mode 100644 index 8f69c457..00000000 --- a/Runtime/Plugins/xNFT.jslib.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: e8b6e98263eeea55d9c24a07b49f8234 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - WebGL: WebGL - second: - enabled: 1 - settings: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs deleted file mode 100644 index c86a61a6..00000000 --- a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs +++ /dev/null @@ -1,50 +0,0 @@ -#if UNITY_WEBGL && UNITY_EDITOR - -using UnityEngine; -using UnityEditor; -using System.IO; - -/// Inspired by Author: Jonas Hahn, Source: https://github.com/Woody4618/Solana.Unity-SDK/blob/main/Runtime/codebase/WebGLTemplatePostProcessor.cs - -/// -/// Since the template is in the packages and Unity wants it to be in the Assets folder we copy it over if it does not -/// yet exists. -/// - -// When UnityEditor.Callbacks.DidReloadScriptsDidReloadScripts we import the WebGL template -// This is needed because the WebGL template is in the package and unity wants it to be in the Assets folder -// So we copy it over if it does not yet exists - - -public class WebGLTemplatesExporter { - [UnityEditor.Callbacks.DidReloadScripts] - private static void OnScriptsReloaded() { - var destinationRootFolder = Path.GetFullPath("Assets/WebGLTemplates/"); - var sourceRootFolder = Path.GetFullPath("Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates/"); - - if (!Directory.Exists("Assets/WebGLTemplates")) - { - Directory.CreateDirectory("Assets/WebGLTemplates"); - } - - // Iterate trough all the template folders in Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates/ and copy them over to Assets/WebGLTemplates - foreach (var templateFolder in Directory.GetDirectories("Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates")) - { - var templateName = Path.GetFileName(templateFolder); - var sourceFolder = Path.Combine(sourceRootFolder, templateName); - var destinationFolder = Path.Combine(destinationRootFolder, templateName); - - if(!Directory.Exists(destinationFolder)) - { - Debug.Log($"Copying template from {sourceFolder} to {destinationFolder}"); - FileUtil.CopyFileOrDirectory(sourceFolder, destinationFolder); - AssetDatabase.Refresh(); - Debug.Log($"Setting webgl template, old was = {PlayerSettings.WebGL.template}"); - } - - } - } - -} - -#endif \ No newline at end of file diff --git a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta deleted file mode 100644 index 3712e794..00000000 --- a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d26bbcb00a0eaa0d098bb5ed7e983e17 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs index f02340f9..b1718c51 100644 --- a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs +++ b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs @@ -22,7 +22,7 @@ public class SolanaWalletAdapterWebGL: WalletBase private static SolanaWalletAdapterWebGLOptions _walletOptions; private static TaskCompletionSource _loginTaskCompletionSource; private static TaskCompletionSource _getWalletsTaskCompletionSource; - private static TaskCompletionSource _loadedScriptTaskCompletionSource; + private static TaskCompletionSource _walletsInitializedTaskCompletionSource; private static TaskCompletionSource _signedTransactionTaskCompletionSource; private static TaskCompletionSource _signedAllTransactionsTaskCompletionSource; private static TaskCompletionSource _signedMessageTaskCompletionSource; @@ -71,22 +71,30 @@ public SolanaWalletAdapterWebGL( } private static async Task InitWallets() { - if (Wallets == null){ - _loadedScriptTaskCompletionSource = new TaskCompletionSource(); - InitWalletAdapter(OnScriptLoaded); - await _loadedScriptTaskCompletionSource.Task; + _currentWallet = null; + _walletsInitializedTaskCompletionSource = new TaskCompletionSource(); + InitWalletAdapter(OnWalletsInitialized); + bool isXnft = await _walletsInitializedTaskCompletionSource.Task; + if (isXnft){ + _currentWallet = new WalletSpecs() + { + name = "XNFT", + icon = "", + installed = true + }; + } else{ + _getWalletsTaskCompletionSource = new TaskCompletionSource(); + ExternGetWallets(OnWalletsLoaded); + var walletsData = await _getWalletsTaskCompletionSource.Task; + Wallets = JsonUtility.FromJson(walletsData).wallets; } - _getWalletsTaskCompletionSource = new TaskCompletionSource(); - ExternGetWallets(OnWalletsLoaded); - var walletsData = await _getWalletsTaskCompletionSource.Task; - Wallets = JsonUtility.FromJson(walletsData).wallets; - } protected override async Task _Login(string password = null) { + Debug.Log("WalletAdapter _Login"); await SetCurrentWallet(); _loginTaskCompletionSource = new TaskCompletionSource(); try @@ -98,29 +106,36 @@ protected override async Task _Login(string password = null) Debug.LogError("WalletAdapter _Login -> Exception: " + e); _loginTaskCompletionSource.SetResult(null); } - WalletAdapterUI.SetActive(false); + if (WalletAdapterUI != null ){ + WalletAdapterUI.SetActive(false); + } return await _loginTaskCompletionSource.Task; } private static async Task SetCurrentWallet() { await InitWallets(); - if (WalletAdapterUI == null) + if (_currentWallet == null) { - WalletAdapterUI = GameObject.Instantiate(_walletOptions.walletAdapterUIPrefab); + if (WalletAdapterUI == null) + { + WalletAdapterUI = GameObject.Instantiate(_walletOptions.walletAdapterUIPrefab); + } + + var waitForWalletSelectionTask = new TaskCompletionSource(); + var walletAdapterScreen = + WalletAdapterUI.transform.GetChild(0).gameObject.GetComponent(); + walletAdapterScreen.viewPortContent = WalletAdapterUI.transform.GetChild(0).Find("Scroll View") + .Find("Viewport").Find("Content").GetComponent(); + walletAdapterScreen.buttonPrefab = _walletOptions.walletAdapterButtonPrefab; + walletAdapterScreen.OnSelectedAction = walletName => + { + waitForWalletSelectionTask.SetResult(walletName); + }; + WalletAdapterUI.SetActive(true); + var walletName = await waitForWalletSelectionTask.Task; + _currentWallet = Array.Find(Wallets, wallet => wallet.name == walletName); } - - var waitForWalletSelectionTask = new TaskCompletionSource(); - var walletAdapterScreen = WalletAdapterUI.transform.GetChild(0).gameObject.GetComponent(); - walletAdapterScreen.viewPortContent = WalletAdapterUI.transform.GetChild(0).Find("Scroll View").Find("Viewport").Find("Content").GetComponent(); - walletAdapterScreen.buttonPrefab = _walletOptions.walletAdapterButtonPrefab; - walletAdapterScreen.OnSelectedAction = walletName => - { - waitForWalletSelectionTask.SetResult(walletName); - }; - WalletAdapterUI.SetActive(true); - var walletName = await waitForWalletSelectionTask.Task; - _currentWallet = Array.Find(Wallets, wallet => wallet.name == walletName); } protected override Task _SignTransaction(Transaction transaction) @@ -218,12 +233,12 @@ public static void OnMessageSigned(string signature) } /// - /// Called from javascript when the wallet adapter script is loaded + /// Called from javascript when the wallet adapter script is loaded. Returns whether it's an XNFT or not. /// [MonoPInvokeCallback(typeof(Action))] - private static void OnScriptLoaded(bool success) + private static void OnWalletsInitialized(bool isXnft) { - _loadedScriptTaskCompletionSource.SetResult(success); + _walletsInitializedTaskCompletionSource.SetResult(isXnft); } /// diff --git a/Runtime/codebase/Web3.cs b/Runtime/codebase/Web3.cs index 20beee2e..dbc68e0b 100644 --- a/Runtime/codebase/Web3.cs +++ b/Runtime/codebase/Web3.cs @@ -137,16 +137,6 @@ public async Task LoginSolanaMobileStack() Wallet = solanaWallet; return acc; } - - public async Task LoginXNFT() - { - var xnftWallet = new XNFTWallet(rpcCluster, customRpc, webSocketsRpc, false); - var acc = await xnftWallet.Login(); - if (acc != null) - Wallet = xnftWallet; - return acc; - } - public async Task LoginWalletAdapter() { diff --git a/Runtime/codebase/WebGLTemplates.meta b/Runtime/codebase/WebGLTemplates.meta deleted file mode 100644 index 74836fa5..00000000 --- a/Runtime/codebase/WebGLTemplates.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a9a0397331c8653cbab367592630193a -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT.meta b/Runtime/codebase/WebGLTemplates/xNFT.meta deleted file mode 100644 index 1d17ae97..00000000 --- a/Runtime/codebase/WebGLTemplates/xNFT.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5a8e2b78429d00b7797b0e6551cb290e -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT/index.html b/Runtime/codebase/WebGLTemplates/xNFT/index.html deleted file mode 100644 index 07459ce9..00000000 --- a/Runtime/codebase/WebGLTemplates/xNFT/index.html +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - Unity XNFT | {{{ PRODUCT_NAME }}}< - - - - - - -
- -
- -
-
-
-
-
- - - \ No newline at end of file diff --git a/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta b/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta deleted file mode 100644 index fb34910d..00000000 --- a/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: bd85919b696f4467ea7c413bb1eb39fb -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png b/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png deleted file mode 100644 index c5a28ff7deafc87894d577474ac556579bd64291..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2184 zcmb_eYd8}O8{VAFVL8Ua#J3J}4tu>A=2&w~n~{-2(VUuWG-t{x6{R#p8%2&oh{ckm zkt`~wUM%v}izy+D#q0g9>-&CuKfmj{uj_v9>$#sl&vie4o~vFSE^;6U2mk=c9Xsmi zy{ojpDJ8L6)#!bcU6Cdp^@{@lWR(6U5KvUCwrc|8yj|=8Os>Ymv^NFfnuI6CIEv>#bJBDbu5rgPW?MW#{@frOv7LB`;n+|zIMydmp09`mj`Yo@9Q4XwOVY`t3SFvV4S8BAiMfg=cBjttu!h3C-Ic~ouGlr>+p zaXAo=S?=_WzRx(AsK8vATcsq|v=i-0lWM9H6&#*8a>$nWMvw*vzJ#rMH-Df?c^_uE zVPUb6OVtyPWF)F3C52kt5uy6JPc0J7$NPvB@Q6x(Fbw?kWG41c#$7Qz^}0;0ieLqj z*Vh+hM9H(LV-1j42BJkK%~6sJ#}i~-wcidR8oPh=gUMTg>%2cP_ZFfMR&1v#l}E&v zBnvx?tvQ)=`=4iE{sE9OwK84qe4l-A^vA;5pgWPW!+l>k&R9D*JAO!^gH-qdZDQJkp^o$W9{HYj&&NYgK+TZ(`4 zUU~=?t#$l2qK7!;1#(;+h+7(z&La9Q{4`24dlp zYO@curjRc;eRw3Y)v_hK$}I+Y^$7A_kvr@PX@EUq)VO{=pm_?4)}@!56nD)`MUJ&N&;czTdUZNw&ghj|?`Z zn$K{a^b^_ifxxN|NzwxZe=HtnaK!gi7<y;4}$t;%NKv#g|M@I!lVy{;Iv#n!Cl`o=|Ne72vNZ&BPuNnqVR??Aa$+ z*C^>bX^jsjvkkg>{G?+Wyw{BM_>=L4ZgJHf&tvqF=+-oRNzn;2d`ymIHf-2yX*Lp? zeR;h}Ju2l>u%_S8R0xD(l%{i|qb1Eev7VC9jxc3_d6I}?y?-L(m!2}6EfSaXOTrWFFTy{CGv8oUr4@ch# z9Dk8Nh1YMX!E||GMaZyY4)O`Qk#~Apr359R+VxJPcW zpgJh7VsqwW12iMn@|Le1?eA7ef@!@XZ-+Fsejhv%6oU{>1!-?W)#6efGpfcy(ZHs& zV~Jp&vYRH?3#odXeH(C-pqiy|CoI!t_*xGN`5E zUH11W-2G=A;(4CoRv@IB&+vj#fTE^@xjJ=83iVz!HG%y(&#iTZJ}`eGSF$`sp-cGM z$qQQ74KZ_Z4teMHV54yAX@2wU=C@c&vmSX@=Dn8+KS3vPK)Uq;YQ)xoKD33{J09HD zE8Fc9re=7gn|Mo|dhLxd{xo%3$5eK2;r}{HL_4V(hb3LgD;ry^T%|zx^c#e>qV|$< zA(pgiqSDbHJK8#T_%~>==R$x=$^jhHshK}2G-P0A*5t-$irUz?F z6pHcL*3I$-b9wiIr99R3FDu`Me^TE)gRAzpZ}Al^piQY)QF~=T^;cHloRn*L2haa& z5dW2|8vXnOnVYV4o##v{H8SuZ;JM&8o6mYgZ@TV4KFRHF6ho)HUL=K&vlSWr-QVZq{;>K?0!+7K+p)|vF+LQi~0@i2tiEF>0tC^E&?OD%y$$cD$4dZm?J8X*(?6jqmHr|1S$`k*htB4+n-0337j KaAevCW&Q=46AE_# diff --git a/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta b/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta deleted file mode 100644 index eb9d217e..00000000 --- a/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 0434dba8138dfbeb3a9c74fe3f5e2cdb -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/codebase/XNFTWallet.cs b/Runtime/codebase/XNFTWallet.cs deleted file mode 100644 index efb909c4..00000000 --- a/Runtime/codebase/XNFTWallet.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using AOT; -using Solana.Unity.Rpc.Models; -using Solana.Unity.Wallet; -using Solana.Unity.Wallet.Utilities; -using UnityEngine; - -// ReSharper disable once CheckNamespace - -namespace Solana.Unity.SDK -{ - public class XNFTWallet: WalletBase - { - - private static TaskCompletionSource _loginTaskCompletionSource; - private static TaskCompletionSource _signedTransactionTaskCompletionSource; - private static TaskCompletionSource _signedMessageTaskCompletionSource; - private static Transaction _currentTransaction; - private static Account _account; - - public XNFTWallet(RpcCluster rpcCluster = RpcCluster.DevNet, string customRpcUri = null, string customStreamingRpcUri = null, bool autoConnectOnStartup = false) - : base(rpcCluster, customRpcUri, customStreamingRpcUri, autoConnectOnStartup) - { - - } - - protected override Task _Login(string password = null) - { - _loginTaskCompletionSource = new TaskCompletionSource(); - try - { - ExternConnectXNFT(OnXNFTConnected); - } - catch (EntryPointNotFoundException) - { - _loginTaskCompletionSource.SetResult(null); - return _loginTaskCompletionSource.Task; - } - return _loginTaskCompletionSource.Task; - } - - protected override Task _SignTransaction(Transaction transaction) - { - _signedTransactionTaskCompletionSource = new TaskCompletionSource(); - var encode = Encoders.Base58.EncodeData(transaction.CompileMessage()); - _currentTransaction = transaction; - ExternSignTransactionXNFT(encode, OnTransactionSigned); - return _signedTransactionTaskCompletionSource.Task; - } - - protected override Task _SignAllTransactions(Transaction[] transactions) - { - throw new NotImplementedException(); - } - - public override Task SignMessage(byte[] message) - { - _signedMessageTaskCompletionSource = new TaskCompletionSource(); - ExternSignMessageXNFT(Convert.ToBase64String(message), OnMessageSigned); - return _signedMessageTaskCompletionSource.Task; - } - - protected override Task _CreateAccount(string mnemonic = null, string password = null) - { - throw new NotImplementedException(); - } - - #region WebGL Callbacks - - /// - /// Called from java script when the xnft approves the connection - /// - [MonoPInvokeCallback(typeof(Action))] - private static void OnXNFTConnected(string walletPubKey) - { - Debug.Log($"Wallet {walletPubKey} connected!"); - _account = new Account("", walletPubKey); - _loginTaskCompletionSource.SetResult(_account); - } - - /// - /// Called from java script when the xnft wallet signed the transaction and return the signature - /// that we then need to put into the transaction before we send it out. - /// - [MonoPInvokeCallback(typeof(Action))] - public static void OnTransactionSigned(string signature) - { - _currentTransaction.Signatures.Add(new SignaturePubKeyPair() - { - PublicKey = _account.PublicKey, - Signature = Encoders.Base58.DecodeData(signature) - }); - _signedTransactionTaskCompletionSource.SetResult(_currentTransaction); - } - - /// - /// Called from java script when the xnft wallet signed the message and return the signature. - /// - [MonoPInvokeCallback(typeof(Action))] - public static void OnMessageSigned(string signature) - { - var signatureArray = JsonUtility.FromJson(signature); - Debug.Log("SignatureArray: " + signatureArray); - _signedMessageTaskCompletionSource.SetResult(signatureArray); - } - - #endregion - - #if UNITY_WEBGL - - [DllImport("__Internal")] - private static extern void ExternConnectXNFT(Action callback); - - [DllImport("__Internal")] - private static extern void ExternSignTransactionXNFT(string transaction, Action callback); - - [DllImport("__Internal")] - private static extern void ExternSignMessageXNFT(string message, Action callback); - - #else - private static void ExternConnectXNFT(Action callback){} - private static void ExternSignTransactionXNFT(string transaction, Action callback){} - private static void ExternSignMessageXNFT(string message, Action callback){} - #endif - } -} \ No newline at end of file diff --git a/Runtime/codebase/XNFTWallet.cs.meta b/Runtime/codebase/XNFTWallet.cs.meta deleted file mode 100644 index 17cb70b2..00000000 --- a/Runtime/codebase/XNFTWallet.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5664e7b366df6aa49bf2054a6a45a11e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Samples~/Solana Wallet/Scripts/example/screens/LoginScreen.cs b/Samples~/Solana Wallet/Scripts/example/screens/LoginScreen.cs index 34ec0626..fd3c7d86 100644 --- a/Samples~/Solana Wallet/Scripts/example/screens/LoginScreen.cs +++ b/Samples~/Solana Wallet/Scripts/example/screens/LoginScreen.cs @@ -54,7 +54,7 @@ private void Start() loginBtnTwitter.onClick.AddListener(delegate{LoginCheckerWeb3Auth(Provider.TWITTER);}); loginBtnWalletAdapter.onClick.AddListener(LoginCheckerWalletAdapter); loginBtnSms.onClick.AddListener(LoginCheckerSms); - loginBtnXNFT.onClick.AddListener(LoginCheckerXnft); + loginBtnXNFT.onClick.AddListener(LoginCheckerWalletAdapter); loginBtnXNFT.gameObject.SetActive(false); @@ -99,19 +99,6 @@ private async void LoginCheckerWeb3Auth(Provider provider) CheckAccount(account); } - public void TryLoginBackPack() - { - LoginCheckerXnft(); - } - - private async void LoginCheckerXnft() - { - if(Web3.Instance == null) return; - var account = await Web3.Instance.LoginXNFT(); - messageTxt.text = ""; - CheckAccount(account); - } - private async void LoginCheckerWalletAdapter() { if(Web3.Instance == null) return; From 2d8d5ec4f88c2d64293cfa359f1d8fb669e912a6 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Tue, 2 May 2023 23:29:19 +0200 Subject: [PATCH 2/7] Fixes InitWalletAdapter when xnft --- .../SolanaWalletAdapterWebGL.jslib | 27 ++++++++++++------- .../SolanaWalletAdapterWebGL.cs | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib index 52ce0793..e78c81d3 100644 --- a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib +++ b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib @@ -1,6 +1,7 @@ mergeInto(LibraryManager.library, { InitWalletAdapter: async function (callback) { // Add UnityWalletAdapter from CDN + const isXnft = Boolean("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined && window.xnft.solana.publicKey != undefined); if(window.walletAdapterLib == undefined){ console.log("Adding WalletAdapterLib") var script = document.createElement("script"); @@ -8,10 +9,10 @@ document.head.appendChild(script); script.onload = function() { console.log("WalletAdapterLib loaded"); - const isXnft = Boolean("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined && window.xnft.solana.publicKey != undefined); - console.log("isXnft: " + isXnft); Module.dynCall_vi(callback, isXnft); }; + }else{ + Module.dynCall_vi(callback, isXnft); } }, ExternGetWallets: async function(callback) { @@ -28,10 +29,11 @@ ExternConnectWallet: async function (walletNamePtr, callback) { try { const walletName = UTF8ToString(walletNamePtr) + var pubKey; if(walletName === 'XNFT'){ - var pubKey = window.xnft.solana.publicKey.toString(); + pubKey = window.xnft.solana.publicKey.toString(); } else { - var pubKey = await window.walletAdapterLib.connectWallet(walletName); + pubKey = await window.walletAdapterLib.connectWallet(walletName); } var bufferSize = lengthBytesUTF8(pubKey) + 1; var pubKeyPtr = _malloc(bufferSize); @@ -45,13 +47,19 @@ try { const walletName = UTF8ToString(walletNamePtr) var base64transaction = UTF8ToString(transactionPtr) + let signedTransaction; if(walletName === 'XNFT'){ + console.log("XNFT Sign Transaction") const transaction = window.walletAdapterLib.getTransactionFromStr(base64transaction); - const signedTransaction = await window.xnft.solana.signTransaction(transaction); + signedTransaction = await window.xnft.solana.signTransaction(transaction); + console.log(signedTransaction) } else { - const signedTransaction = await window.walletAdapterLib.signTransaction(walletName, base64transaction); + console.log("Sign Transaction") + signedTransaction = await window.walletAdapterLib.signTransaction(walletName, base64transaction); + console.log(signedTransaction) } - var signature = signedTransaction.signature.toString('base64'); + let signature = signedTransaction.signature.toString('base64'); + console.log(signature) var bufferSize = lengthBytesUTF8(signature) + 1; var signaturePtr = _malloc(bufferSize); stringToUTF8(signature, signaturePtr, bufferSize); @@ -64,13 +72,14 @@ try { const walletName = UTF8ToString(walletNamePtr) var base64Message = UTF8ToString(messagePtr) + var signatureStr; if(walletName === 'XNFT'){ const messageBytes = Uint8Array.from(atob(base64Message), (c) => c.charCodeAt(0)); const signedMessage = await window.xnft.solana.signMessage(messageBytes); - var signatureStr = JSON.stringify(Array.from(signedMessage)); + signatureStr = JSON.stringify(Array.from(signedMessage)); } else { var signature = await window.walletAdapterLib.signMessage(walletName, base64Message); - var signatureStr = signature.toString('base64'); + signatureStr = signature.toString('base64'); } var bufferSize = lengthBytesUTF8(signatureStr) + 1; var signaturePtr = _malloc(bufferSize); diff --git a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs index b1718c51..f98cc928 100644 --- a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs +++ b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs @@ -194,6 +194,7 @@ private static void OnWalletConnected(string walletPubKey) [MonoPInvokeCallback(typeof(Action))] public static void OnTransactionSigned(string signature) { + Debug.Log($"Transaction signed: {signature}"); _currentTransaction.Signatures.Add(new SignaturePubKeyPair() { PublicKey = _account.PublicKey, From 8cd178cde544a0d421c242d99179451d7a522cb4 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Thu, 11 May 2023 09:51:27 +0200 Subject: [PATCH 3/7] remove logs and implement --- .../SolanaWalletAdapterWebGL.jslib | 22 ++++++++++++------- .../SolanaWalletAdapterWebGL.cs | 2 -- Runtime/codebase/Web3.cs | 9 -------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib index e78c81d3..4ad53e0d 100644 --- a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib +++ b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib @@ -1,7 +1,8 @@ mergeInto(LibraryManager.library, { InitWalletAdapter: async function (callback) { - // Add UnityWalletAdapter from CDN + const isXnft = Boolean("xnft" in window && window.xnft != undefined && window.xnft.solana != undefined && window.xnft.solana.publicKey != undefined); + // Add UnityWalletAdapter from CDN if(window.walletAdapterLib == undefined){ console.log("Adding WalletAdapterLib") var script = document.createElement("script"); @@ -49,17 +50,12 @@ var base64transaction = UTF8ToString(transactionPtr) let signedTransaction; if(walletName === 'XNFT'){ - console.log("XNFT Sign Transaction") const transaction = window.walletAdapterLib.getTransactionFromStr(base64transaction); signedTransaction = await window.xnft.solana.signTransaction(transaction); - console.log(signedTransaction) } else { - console.log("Sign Transaction") signedTransaction = await window.walletAdapterLib.signTransaction(walletName, base64transaction); - console.log(signedTransaction) } let signature = signedTransaction.signature.toString('base64'); - console.log(signature) var bufferSize = lengthBytesUTF8(signature) + 1; var signaturePtr = _malloc(bufferSize); stringToUTF8(signature, signaturePtr, bufferSize); @@ -72,7 +68,7 @@ try { const walletName = UTF8ToString(walletNamePtr) var base64Message = UTF8ToString(messagePtr) - var signatureStr; + let signatureStr; if(walletName === 'XNFT'){ const messageBytes = Uint8Array.from(atob(base64Message), (c) => c.charCodeAt(0)); const signedMessage = await window.xnft.solana.signMessage(messageBytes); @@ -94,7 +90,17 @@ const walletName = UTF8ToString(walletNamePtr) var base64transactionsStr = UTF8ToString(transactionsPtr) var base64transactions = base64transactionsStr.split(','); - var signedTransactions = await window.walletAdapterLib.signAllTransactions(walletName, base64transactions); + let signedTransactions; + if(walletName === 'XNFT'){ + let transactions = []; + for(var i = 0; i < base64transactions.length; i++){ + const transaction = window.walletAdapterLib.getTransactionFromStr(base64transactions[i]); + transactions.push(transaction); + } + signedTransactions = await window.xnft.solana.signAllTransactions(transactions); + } else { + signedTransactions = await window.walletAdapterLib.signAllTransactions(walletName, base64transactions); + } var signatures = []; for (var i = 0; i < signedTransactions.length; i++) { var signedTransaction = signedTransactions[i]; diff --git a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs index f98cc928..0712500d 100644 --- a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs +++ b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs @@ -94,7 +94,6 @@ private static async Task InitWallets() { protected override async Task _Login(string password = null) { - Debug.Log("WalletAdapter _Login"); await SetCurrentWallet(); _loginTaskCompletionSource = new TaskCompletionSource(); try @@ -194,7 +193,6 @@ private static void OnWalletConnected(string walletPubKey) [MonoPInvokeCallback(typeof(Action))] public static void OnTransactionSigned(string signature) { - Debug.Log($"Transaction signed: {signature}"); _currentTransaction.Signatures.Add(new SignaturePubKeyPair() { PublicKey = _account.PublicKey, diff --git a/Runtime/codebase/Web3.cs b/Runtime/codebase/Web3.cs index 37dccc8a..4a8e92b6 100644 --- a/Runtime/codebase/Web3.cs +++ b/Runtime/codebase/Web3.cs @@ -176,15 +176,6 @@ public async Task LoginSolanaMobileStack() return acc; } - public async Task LoginXNFT() - { - var xnftWallet = new XNFTWallet(rpcCluster, customRpc, webSocketsRpc, false); - var acc = await xnftWallet.Login(); - if (acc != null) - WalletBase = xnftWallet; - return acc; - } - public async Task LoginWalletAdapter() { From 922bae620eb31896e48f809a58b4c07c7022642a Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Thu, 11 May 2023 13:33:37 +0200 Subject: [PATCH 4/7] Removed LoginXNFT - XNFTWallet does not exist anymore --- Runtime/codebase/Web3.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Runtime/codebase/Web3.cs b/Runtime/codebase/Web3.cs index a49c139b..8b8912f7 100644 --- a/Runtime/codebase/Web3.cs +++ b/Runtime/codebase/Web3.cs @@ -141,8 +141,6 @@ private void Start() if(w == null) return; WalletBase = _web3AuthWallet; }; - // Try to login if running as an XNFT - LoginXNFT().AsUniTask().Forget(); } catch (Exception e) { @@ -190,22 +188,7 @@ public async Task LoginInWeb3Auth(Provider provider) WalletBase = _web3AuthWallet; return acc; } - - /// - /// Login to backpack, if running as an xnft - /// - /// - public async Task LoginXNFT() - { - var xnftWallet = new XNFTWallet(rpcCluster, customRpc, webSocketsRpc, false); - var acc = await xnftWallet.Login(); - if (acc != null) - WalletBase = xnftWallet; - return acc; - } - - /// /// Login using the solana wallet adapter /// From b9d17b7910640ebbe47f4d5c736b263c15a28de0 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Thu, 11 May 2023 13:53:42 +0200 Subject: [PATCH 5/7] Update SolanaWalletAdapterWebGL.jslib --- .../SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib index 4ad53e0d..566ef92d 100644 --- a/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib +++ b/Runtime/Plugins/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.jslib @@ -6,7 +6,7 @@ if(window.walletAdapterLib == undefined){ console.log("Adding WalletAdapterLib") var script = document.createElement("script"); - script.src = "https://cdn.jsdelivr.net/gh/magicblock-labs/unity-js-wallet-adapter@xnft-helpers/dist/wallet-adapter-lib.js"; + script.src = "https://cdn.jsdelivr.net/gh/magicblock-labs/unity-js-wallet-adapter@main/dist/wallet-adapter-lib.js"; document.head.appendChild(script); script.onload = function() { console.log("WalletAdapterLib loaded"); From cd39ad50b2c04f88772558f8d1a7fe4cf25ca7c0 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Fri, 12 May 2023 11:33:20 +0200 Subject: [PATCH 6/7] Recovered WebGLTemplatesExporter and xNFT template, removed unnecessary script injections and fixed Loader Filename --- .../Exporters/WebGLTemplatesExporter.cs | 50 +++++++++ .../Exporters/WebGLTemplatesExporter.cs.meta | 3 + Runtime/codebase/WebGLTemplates.meta | 8 ++ Runtime/codebase/WebGLTemplates/xNFT.meta | 8 ++ .../codebase/WebGLTemplates/xNFT/index.html | 102 ++++++++++++++++++ .../WebGLTemplates/xNFT/index.html.meta | 7 ++ .../WebGLTemplates/xNFT/thumbnail.png | Bin 0 -> 2184 bytes .../WebGLTemplates/xNFT/thumbnail.png.meta | 7 ++ 8 files changed, 185 insertions(+) create mode 100644 Runtime/codebase/Exporters/WebGLTemplatesExporter.cs create mode 100644 Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta create mode 100644 Runtime/codebase/WebGLTemplates.meta create mode 100644 Runtime/codebase/WebGLTemplates/xNFT.meta create mode 100644 Runtime/codebase/WebGLTemplates/xNFT/index.html create mode 100644 Runtime/codebase/WebGLTemplates/xNFT/index.html.meta create mode 100644 Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png create mode 100644 Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta diff --git a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs new file mode 100644 index 00000000..fb2b36f8 --- /dev/null +++ b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs @@ -0,0 +1,50 @@ +#if UNITY_WEBGL && UNITY_EDITOR + +using UnityEngine; +using UnityEditor; +using System.IO; + +/// Inspired by Author: Jonas Hahn, Source: https://github.com/Woody4618/Solana.Unity-SDK/blob/main/Runtime/codebase/WebGLTemplatePostProcessor.cs + +/// +/// Since the template is in the packages and Unity wants it to be in the Assets folder we copy it over if it does not +/// yet exists. +/// + +// When UnityEditor.Callbacks.DidReloadScriptsDidReloadScripts we import the WebGL template +// This is needed because the WebGL template is in the package and unity wants it to be in the Assets folder +// So we copy it over if it does not yet exists + + +public class WebGLTemplatesExporter { + [UnityEditor.Callbacks.DidReloadScripts] + private static void OnScriptsReloaded() { + var destinationRootFolder = Path.GetFullPath("Assets/WebGLTemplates/"); + var sourceRootFolder = Path.GetFullPath("Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates/"); + + if (!Directory.Exists("Assets/WebGLTemplates")) + { + Directory.CreateDirectory("Assets/WebGLTemplates"); + } + + // Iterate trough all the template folders in Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates/ and copy them over to Assets/WebGLTemplates + foreach (var templateFolder in Directory.GetDirectories("Packages/com.solana.unity_sdk/Runtime/codebase/WebGLTemplates")) + { + var templateName = Path.GetFileName(templateFolder); + var sourceFolder = Path.Combine(sourceRootFolder, templateName); + var destinationFolder = Path.Combine(destinationRootFolder, templateName); + + if(!Directory.Exists(destinationFolder)) + { + Debug.Log($"Copying template from {sourceFolder} to {destinationFolder}"); + FileUtil.CopyFileOrDirectory(sourceFolder, destinationFolder); + AssetDatabase.Refresh(); + Debug.Log($"Setting webgl template, old was = {PlayerSettings.WebGL.template}"); + } + + } + } + +} + +#endif \ No newline at end of file diff --git a/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta new file mode 100644 index 00000000..47c0ab9d --- /dev/null +++ b/Runtime/codebase/Exporters/WebGLTemplatesExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d41289880070433aa49f34521a109e46 +timeCreated: 1683883584 \ No newline at end of file diff --git a/Runtime/codebase/WebGLTemplates.meta b/Runtime/codebase/WebGLTemplates.meta new file mode 100644 index 00000000..74836fa5 --- /dev/null +++ b/Runtime/codebase/WebGLTemplates.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a9a0397331c8653cbab367592630193a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT.meta b/Runtime/codebase/WebGLTemplates/xNFT.meta new file mode 100644 index 00000000..1d17ae97 --- /dev/null +++ b/Runtime/codebase/WebGLTemplates/xNFT.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a8e2b78429d00b7797b0e6551cb290e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT/index.html b/Runtime/codebase/WebGLTemplates/xNFT/index.html new file mode 100644 index 00000000..ebabd186 --- /dev/null +++ b/Runtime/codebase/WebGLTemplates/xNFT/index.html @@ -0,0 +1,102 @@ + + + + + + Unity XNFT | {{{ PRODUCT_NAME }}}< + + + + +
+ +
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta b/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta new file mode 100644 index 00000000..fb34910d --- /dev/null +++ b/Runtime/codebase/WebGLTemplates/xNFT/index.html.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bd85919b696f4467ea7c413bb1eb39fb +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png b/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png new file mode 100644 index 0000000000000000000000000000000000000000..c5a28ff7deafc87894d577474ac556579bd64291 GIT binary patch literal 2184 zcmb_eYd8}O8{VAFVL8Ua#J3J}4tu>A=2&w~n~{-2(VUuWG-t{x6{R#p8%2&oh{ckm zkt`~wUM%v}izy+D#q0g9>-&CuKfmj{uj_v9>$#sl&vie4o~vFSE^;6U2mk=c9Xsmi zy{ojpDJ8L6)#!bcU6Cdp^@{@lWR(6U5KvUCwrc|8yj|=8Os>Ymv^NFfnuI6CIEv>#bJBDbu5rgPW?MW#{@frOv7LB`;n+|zIMydmp09`mj`Yo@9Q4XwOVY`t3SFvV4S8BAiMfg=cBjttu!h3C-Ic~ouGlr>+p zaXAo=S?=_WzRx(AsK8vATcsq|v=i-0lWM9H6&#*8a>$nWMvw*vzJ#rMH-Df?c^_uE zVPUb6OVtyPWF)F3C52kt5uy6JPc0J7$NPvB@Q6x(Fbw?kWG41c#$7Qz^}0;0ieLqj z*Vh+hM9H(LV-1j42BJkK%~6sJ#}i~-wcidR8oPh=gUMTg>%2cP_ZFfMR&1v#l}E&v zBnvx?tvQ)=`=4iE{sE9OwK84qe4l-A^vA;5pgWPW!+l>k&R9D*JAO!^gH-qdZDQJkp^o$W9{HYj&&NYgK+TZ(`4 zUU~=?t#$l2qK7!;1#(;+h+7(z&La9Q{4`24dlp zYO@curjRc;eRw3Y)v_hK$}I+Y^$7A_kvr@PX@EUq)VO{=pm_?4)}@!56nD)`MUJ&N&;czTdUZNw&ghj|?`Z zn$K{a^b^_ifxxN|NzwxZe=HtnaK!gi7<y;4}$t;%NKv#g|M@I!lVy{;Iv#n!Cl`o=|Ne72vNZ&BPuNnqVR??Aa$+ z*C^>bX^jsjvkkg>{G?+Wyw{BM_>=L4ZgJHf&tvqF=+-oRNzn;2d`ymIHf-2yX*Lp? zeR;h}Ju2l>u%_S8R0xD(l%{i|qb1Eev7VC9jxc3_d6I}?y?-L(m!2}6EfSaXOTrWFFTy{CGv8oUr4@ch# z9Dk8Nh1YMX!E||GMaZyY4)O`Qk#~Apr359R+VxJPcW zpgJh7VsqwW12iMn@|Le1?eA7ef@!@XZ-+Fsejhv%6oU{>1!-?W)#6efGpfcy(ZHs& zV~Jp&vYRH?3#odXeH(C-pqiy|CoI!t_*xGN`5E zUH11W-2G=A;(4CoRv@IB&+vj#fTE^@xjJ=83iVz!HG%y(&#iTZJ}`eGSF$`sp-cGM z$qQQ74KZ_Z4teMHV54yAX@2wU=C@c&vmSX@=Dn8+KS3vPK)Uq;YQ)xoKD33{J09HD zE8Fc9re=7gn|Mo|dhLxd{xo%3$5eK2;r}{HL_4V(hb3LgD;ry^T%|zx^c#e>qV|$< zA(pgiqSDbHJK8#T_%~>==R$x=$^jhHshK}2G-P0A*5t-$irUz?F z6pHcL*3I$-b9wiIr99R3FDu`Me^TE)gRAzpZ}Al^piQY)QF~=T^;cHloRn*L2haa& z5dW2|8vXnOnVYV4o##v{H8SuZ;JM&8o6mYgZ@TV4KFRHF6ho)HUL=K&vlSWr-QVZq{;>K?0!+7K+p)|vF+LQi~0@i2tiEF>0tC^E&?OD%y$$cD$4dZm?J8X*(?6jqmHr|1S$`k*htB4+n-0337j KaAevCW&Q=46AE_# literal 0 HcmV?d00001 diff --git a/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta b/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta new file mode 100644 index 00000000..eb9d217e --- /dev/null +++ b/Runtime/codebase/WebGLTemplates/xNFT/thumbnail.png.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0434dba8138dfbeb3a9c74fe3f5e2cdb +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From e7811ddf8fb6fedcfd6dac40b971907ed3891965 Mon Sep 17 00:00:00 2001 From: Nicolas Francisquelo Tacca Date: Fri, 12 May 2023 13:49:00 +0200 Subject: [PATCH 7/7] Auto connect if is XNFT --- .../SolanaWalletAdapterWebGL.cs | 12 ++++++++++-- Runtime/codebase/Web3.cs | 18 ++++++++++++++++++ .../Scripts/example/DropdownClusterSelector.cs | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs index 5d704fa2..b6bbee88 100644 --- a/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs +++ b/Runtime/codebase/SolanaWalletAdapterWebGL/SolanaWalletAdapterWebGL.cs @@ -90,8 +90,16 @@ private static async Task InitWallets() { Wallets = JsonUtility.FromJson(walletsData).wallets; } } - - + + + /// + /// Check whether it's an XNFT or not + /// + /// true if it's an XNFT, false otherwise + public static async Task IsXnft(){ + await InitWallets(); + return _currentWallet != null && _currentWallet.name == "XNFT"; + } protected override async Task _Login(string password = null) { diff --git a/Runtime/codebase/Web3.cs b/Runtime/codebase/Web3.cs index 8b8912f7..0fecf525 100644 --- a/Runtime/codebase/Web3.cs +++ b/Runtime/codebase/Web3.cs @@ -146,6 +146,12 @@ private void Start() { Debug.Log("We3Auth session not detected, " + e.Message); } + + #if UNITY_WEBGL + LoginXNFT().AsUniTask().Forget(); + #endif + + } /// @@ -188,6 +194,18 @@ public async Task LoginInWeb3Auth(Provider provider) WalletBase = _web3AuthWallet; return acc; } + + public async Task LoginXNFT() + { + var isXnft = await SolanaWalletAdapterWebGL.IsXnft(); + if (isXnft) + { + Debug.Log("xNFT detected"); + return await LoginWalletAdapter(); + } + Debug.Log("xNFT not detected"); + return null; + } /// /// Login using the solana wallet adapter diff --git a/Samples~/Solana Wallet/Scripts/example/DropdownClusterSelector.cs b/Samples~/Solana Wallet/Scripts/example/DropdownClusterSelector.cs index 195b0b3f..5d3699de 100644 --- a/Samples~/Solana Wallet/Scripts/example/DropdownClusterSelector.cs +++ b/Samples~/Solana Wallet/Scripts/example/DropdownClusterSelector.cs @@ -1,6 +1,7 @@ using Solana.Unity.SDK; using TMPro; using UnityEngine; +using Cysharp.Threading.Tasks; // ReSharper disable once CheckNamespace @@ -32,5 +33,6 @@ public void RpcNodeDropdownSelected(int value) }; PlayerPrefs.SetInt("rpcCluster", value); PlayerPrefs.Save(); + Web3.Instance.LoginXNFT().AsUniTask().Forget(); } }