Skip to content

Commit

Permalink
Wallet download helper cache issue (#125)
Browse files Browse the repository at this point in the history
* caching issue fix

* load wallet images in parallel
  • Loading branch information
Antivortex authored Apr 18, 2023
1 parent 4c52477 commit bf2e191
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace MirageSDK.WalletConnect.VersionShared.Utils
{
public static class WalletDownloadHelper
{
private static Dictionary<string, WalletEntry> _walletEntriesCache = new Dictionary<string, WalletEntry>();
private static Dictionary<string, WalletEntry> _walletEntriesCache;

public static async UniTask<WalletEntry> FindWalletEntryByName(string walletName, bool invalidateCache = false)
{
Expand Down Expand Up @@ -84,21 +84,36 @@ public static async UniTask<Dictionary<string, WalletEntry>> FetchWalletList(boo
return supportedWallets;
}

var filteredSupportedWallets = GetAllSupportedWallets(walletconnectSupportedWallets: supportedWallets);
foreach (var wallet in filteredSupportedWallets.Values)
var filteredSupportedWallets = GetAllSupportedWallets(walletConnectSupportedWallets: supportedWallets);

if (filteredSupportedWallets != null)
{
await wallet.DownloadImages();
var listOfTasks = new List<UniTask>();
foreach (var wallet in filteredSupportedWallets.Values)
{
var downloadTask = wallet.DownloadImages();
listOfTasks.Add(downloadTask);
}

await UniTask.WhenAll(listOfTasks);
}

_walletEntriesCache = filteredSupportedWallets;

return filteredSupportedWallets;
}
}

private static Dictionary<string, WalletEntry> GetAllSupportedWallets(
Dictionary<string, WalletEntry> walletconnectSupportedWallets)
Dictionary<string, WalletEntry> walletConnectSupportedWallets)
{
if (walletConnectSupportedWallets == null)
{
return null;
}

var walletsSupportedBySDK = WalletNameHelper.GetSupportedWalletNames();
return walletconnectSupportedWallets
return walletConnectSupportedWallets
.Where(predicate: w => walletsSupportedBySDK.Contains(value: w.Value.name))
.ToDictionary(keySelector: i => i.Key, elementSelector: i => i.Value);
}
Expand Down

0 comments on commit bf2e191

Please sign in to comment.