Skip to content

Commit f68489f

Browse files
author
Ovidiu Arion
committed
working link
1 parent d058435 commit f68489f

File tree

1 file changed

+52
-63
lines changed
  • Assets/ExternalTools/WalletConnectUnity/Scripts/WalletConnectSharp.Unity

1 file changed

+52
-63
lines changed

Assets/ExternalTools/WalletConnectUnity/Scripts/WalletConnectSharp.Unity/WalletConnect.cs

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ namespace WalletConnectSharp.Unity
2525
public class WalletConnect : BindableMonoBehavior
2626
{
2727
public const string SessionKey = "__WALLETCONNECT_SESSION__";
28-
28+
2929
public Dictionary<string, AppEntry> SupportedWallets
3030
{
3131
get;
3232
private set;
3333
}
34-
34+
3535
public AppEntry SelectedWallet { get; set; }
3636

3737
public Wallets DefaultWallet;
@@ -42,7 +42,7 @@ public class WalletConnectEventNoSession : UnityEvent { }
4242
public class WalletConnectEventWithSession : UnityEvent<WalletConnectUnitySession> { }
4343
[Serializable]
4444
public class WalletConnectEventWithSessionData : UnityEvent<WCSessionData> { }
45-
45+
4646
public event EventHandler ConnectionStarted;
4747
public event EventHandler NewSessionStarted;
4848

@@ -58,7 +58,7 @@ public static WalletConnect Instance
5858
return _instance;
5959
}
6060
}
61-
61+
6262
public static WalletConnectUnitySession ActiveSession
6363
{
6464
get
@@ -82,15 +82,15 @@ public string ConnectURL
8282
public bool createNewSessionOnSessionDisconnect = true;
8383
public int connectSessionRetryCount = 3;
8484
public string customBridgeUrl;
85-
85+
8686
public int chainId = 1;
8787

8888
public WalletConnectEventNoSession ConnectedEvent;
8989

9090
public WalletConnectEventWithSessionData ConnectedEventSession;
9191

9292
public WalletConnectEventWithSession DisconnectedEvent;
93-
93+
9494
public WalletConnectEventWithSession ConnectionFailedEvent;
9595
public WalletConnectEventWithSession NewSessionConnected;
9696
public WalletConnectEventWithSession ResumedSessionConnected;
@@ -102,7 +102,8 @@ public WalletConnectUnitySession Session
102102
}
103103

104104
[Obsolete("Use Session instead of Protocol")]
105-
public WalletConnectUnitySession Protocol {
105+
public WalletConnectUnitySession Protocol
106+
{
106107
get { return Session; }
107108
private set
108109
{
@@ -140,8 +141,8 @@ protected override async void Awake()
140141
await Connect();
141142
}
142143
}
143-
144-
async void Start()
144+
145+
async void Start()
145146
{
146147
if (connectOnStart && !connectOnAwake)
147148
{
@@ -216,7 +217,7 @@ public async Task<WCSessionData> Connect()
216217

217218
#if UNITY_WEBGL
218219
ciper = new WebGlAESCipher();
219-
#endif
220+
#endif
220221

221222
if (savedSession != null)
222223
{
@@ -237,32 +238,32 @@ public async Task<WCSessionData> Connect()
237238

238239
return await CompleteConnect();
239240
}
240-
catch(TimeoutException)
241+
catch (TimeoutException)
241242
{
242243
Debug.Log("Timeout Reached, Regenerating Session");
243244
}
244245
}
245-
246+
246247
}
247248

248249
private void SetupEvents()
249250
{
250-
#if UNITY_EDITOR || DEBUG
251+
#if UNITY_EDITOR || DEBUG
251252
//Useful for debug logging
252253
Session.OnSessionConnect += (sender, session) =>
253254
{
254255
Debug.Log("[WalletConnect] Session Connected");
255256
};
256-
#endif
257-
257+
#endif
258+
258259
Session.OnSessionDisconnect += SessionOnOnSessionDisconnect;
259260
Session.OnSessionCreated += SessionOnOnSessionCreated;
260261
Session.OnSessionResumed += SessionOnOnSessionResumed;
261-
262-
#if UNITY_ANDROID || UNITY_IOS
262+
263+
#if UNITY_ANDROID || UNITY_IOS
263264
//Whenever we send a request to the Wallet, we want to open the Wallet app
264265
Session.OnSend += (sender, session) => OpenMobileWallet();
265-
#endif
266+
#endif
266267
}
267268

268269
private void TeardownEvents()
@@ -287,15 +288,15 @@ private void SessionOnOnSessionCreated(object sender, WalletConnectSession e)
287288
private async Task<WCSessionData> CompleteConnect()
288289
{
289290
Debug.Log("Waiting for Wallet connection");
290-
291+
291292
if (ConnectionStarted != null)
292293
{
293294
ConnectionStarted(this, EventArgs.Empty);
294295
}
295-
296+
296297
WalletConnectEventWithSessionData allEvents = new WalletConnectEventWithSessionData();
297-
298-
allEvents.AddListener(delegate(WCSessionData arg0)
298+
299+
allEvents.AddListener(delegate (WCSessionData arg0)
299300
{
300301
ConnectedEvent.Invoke();
301302
ConnectedEventSession.Invoke(arg0);
@@ -320,7 +321,7 @@ private async Task<WCSessionData> CompleteConnect()
320321
throw new IOException("Failed to request session connection after " + tries + " times.", e);
321322
}
322323
}
323-
324+
324325
throw new IOException("Failed to request session connection after " + tries + " times.");
325326
}
326327

@@ -333,9 +334,9 @@ private async void SessionOnOnSessionDisconnect(object sender, EventArgs e)
333334
{
334335
PlayerPrefs.DeleteKey(SessionKey);
335336
}
336-
337+
337338
TeardownEvents();
338-
339+
339340
if (createNewSessionOnSessionDisconnect)
340341
{
341342
await Connect();
@@ -366,9 +367,9 @@ private IEnumerator DownloadImagesFor(string id, string[] sizes = null)
366367
{
367368
if (sizes == null)
368369
{
369-
sizes = new string[] {"sm", "md", "lg"};
370+
sizes = new string[] { "sm", "md", "lg" };
370371
}
371-
372+
372373
var data = SupportedWallets[id];
373374

374375
foreach (var size in sizes)
@@ -385,7 +386,7 @@ private IEnumerator DownloadImagesFor(string id, string[] sizes = null)
385386
}
386387
else
387388
{
388-
var texture = ((DownloadHandlerTexture) imageRequest.downloadHandler).texture;
389+
var texture = ((DownloadHandlerTexture)imageRequest.downloadHandler).texture;
389390
var sprite = Sprite.Create(texture,
390391
new Rect(0.0f, 0.0f, texture.width, texture.height),
391392
new Vector2(0.5f, 0.5f), 100.0f);
@@ -413,7 +414,7 @@ public IEnumerator FetchWalletList(bool downloadImages = true)
413414
{
414415
// Request and wait for the desired page.
415416
yield return webRequest.SendWebRequest();
416-
417+
417418
if (webRequest.isNetworkError)
418419
{
419420
Debug.Log("Error Getting Wallet Info: " + webRequest.error);
@@ -461,7 +462,7 @@ private async Task SaveOrDisconnect()
461462
{
462463
if (!Session.Connected)
463464
return;
464-
465+
465466
if (autoSaveAndResume)
466467
{
467468
var session = Session.SaveSession();
@@ -479,14 +480,14 @@ private async Task SaveOrDisconnect()
479480
public void OpenMobileWallet(AppEntry selectedWallet)
480481
{
481482
SelectedWallet = selectedWallet;
482-
483+
483484
OpenMobileWallet();
484485
}
485-
486+
486487
public void OpenDeepLink(AppEntry selectedWallet)
487488
{
488489
SelectedWallet = selectedWallet;
489-
490+
490491
OpenDeepLink();
491492
}
492493

@@ -502,31 +503,19 @@ public void OpenMobileWallet()
502503
Application.OpenURL(maiarUrl);
503504

504505
//Application.OpenURL(signingURL);
505-
#elif UNITY_IOS && UNITY_EDITOR
506-
//if (SelectedWallet == null)
507-
//{
508-
// throw new NotImplementedException(
509-
// "You must use OpenMobileWallet(AppEntry) or set SelectedWallet on iOS!");
510-
//}
511-
//else
512-
//{
513-
// string url;
514-
// string encodedConnect = WebUtility.UrlEncode(ConnectURL);
515-
// if (!string.IsNullOrWhiteSpace(SelectedWallet.mobile.universal))
516-
// {
517-
// url = SelectedWallet.mobile.universal + "/wc?uri=" + encodedConnect;
518-
// }
519-
// else
520-
// {
521-
// url = SelectedWallet.mobile.native + (SelectedWallet.mobile.native.EndsWith(":") ? "//" : "/") +
522-
// "wc?uri=" + encodedConnect;
523-
// }
524-
525-
// var signingUrl = url.Split('?')[0];
526-
527-
// Debug.Log("Opening: " + signingUrl);
528-
// Application.OpenURL(signingUrl);
529-
//}
506+
#elif UNITY_IOS
507+
508+
string url;
509+
string encodedConnect = WebUtility.UrlEncode(ConnectURL);
510+
511+
url = "https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://maiar.com" + "/wc?uri=" + encodedConnect;
512+
513+
514+
var signingUrl = url.Split('?')[0];
515+
516+
Debug.Log("Opening: " + signingUrl);
517+
Application.OpenURL(signingUrl);
518+
530519
#else
531520
Debug.Log("Platform does not support deep linking");
532521
return;
@@ -542,7 +531,7 @@ public void OpenDeepLink()
542531

543532
return;
544533
}
545-
534+
546535
#if UNITY_ANDROID
547536
Debug.Log("[WalletConnect] Opening URL: " + ConnectURL);
548537
Application.OpenURL(ConnectURL);
@@ -565,7 +554,7 @@ public void OpenDeepLink()
565554
url = SelectedWallet.mobile.native + (SelectedWallet.mobile.native.EndsWith(":") ? "//" : "/") +
566555
"wc?uri=" + encodedConnect;
567556
}
568-
557+
569558
Debug.Log("Opening: " + url);
570559
Application.OpenURL(url);
571560
}
@@ -579,14 +568,14 @@ public void CLearSession()
579568
{
580569
PlayerPrefs.DeleteKey(SessionKey);
581570
}
582-
571+
583572
public async void CloseSession(bool waitForNewSession = true)
584573
{
585574
if (ActiveSession == null)
586575
return;
587-
576+
588577
await ActiveSession.Disconnect();
589-
578+
590579
if (waitForNewSession)
591580
await ActiveSession.Connect();
592581
}

0 commit comments

Comments
 (0)