-
Notifications
You must be signed in to change notification settings - Fork 180
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
[WCM] Detect installed wallets #991
Conversation
<string>zerion</string> | ||
<string>rainbow</string> | ||
<string>spot</string> | ||
</array> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just food for thought:
A long time ago I tried to solve the problem with the manual editing of supported wallet lists and stopped at some point. I'm not sure whether it makes sense at all, but maybe you will find it useful and polish it into a solid solution.
It is possible to modify LSApplicationQuerySchemes
on compile using some script i.e.
BASE_PLIST="${SRCROOT}/WalletApp/Other/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :LSApplicationQueriesSchemes array' "$BASE_PLIST"
/usr/libexec/PlistBuddy -c 'Add :LSApplicationQueriesSchemes: string metamask' "$BASE_PLIST"
/usr/libexec/PlistBuddy -c 'Add :LSApplicationQueriesSchemes: string trust' "$BASE_PLIST"
/usr/libexec/PlistBuddy -c 'Add :LSApplicationQueriesSchemes: string showcase' "$BASE_PLIST"
If you want to support this list dynamically (explorer api what not) it is also possible to request them while building, smth like:
WALLETS_SCHEME=${TEMP_DIR}/wallets-scheme.json
BASE_PLIST="${SRCROOT}/WalletApp/Other/Info.plist"
curl -o $WALLETS_SCHEME https://walletconnect.com/wallets-scheme.json
jq -c '.[]' $WALLETS_SCHEME | while read scheme; do
/usr/libexec/PlistBuddy -c 'Add :LSApplicationQueriesSchemes: string $scheme' "$BASE_PLIST"
done
For developers, it will be enough to add the script above to Build Phases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a great way how to deal with it forward, but for now, we are sticking to simple solution and mentioning it in docs that in order to detect installed wallets they need to populate these LSApplicationQueriesSchemes
} | ||
} | ||
} | ||
|
||
func loadRecentWallets() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that ModalViewModel
is going to be a bit overloaded with this "Recent Wallets" logic and it looks a bit like a good place for potential bugs because of sorting/comparing/adding/moving/removing. I do not claim that there are bugs, but I would use more stable solution for such a task as LRU Cache algorithm.
You can create a separate object, which will be responsible for storing and handling recent objects limited by capacity, and add some tests to make sure this always works as expected.
But it's not mandatory, just another food for thought 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved some of the logic to the RecentWalletsStorage
object and tidied up the sorting logic to be more declarative.
b6ff428
to
e4af0a5
Compare
a03178c
to
9f7efb8
Compare
input.sorted { lhs, rhs in | ||
guard let lhsLastTimeUsed = lhs.lastTimeUsed else { | ||
func sortByOrder() -> [Listing] { | ||
self.sorted { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I understand every sort iterations: sortByOrder
, sortByInstalled
... will trigger UI update es wallets is @published. Is here any was to do it in one UI update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since it is in a single computed property like this, which does not sort in place but returns a new ordered sequence, it should trigger a single UI update once it orders everything.
var filteredWallets: [Listing] {
wallets
.sortByOrder()
.sortByInstalled()
.sortByRecent()
.filter(searchTerm: searchTerm)
}
One concern might be that we are doing unnecessary iterations since order
and installed
won't change, so I will extract those to run only once.
func loadRecentWallets() { | ||
recentWalletStorage.recentWallets.forEach { wallet in | ||
guard let lastTimeUsed = wallet.lastTimeUsed else { return } | ||
setLastTimeUsed(wallet.id, date: lastTimeUsed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have wallet instance here, why we need to search wallet by id in setLastTimeUsed again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wallet instance here is the one loaded from UserDefaults, while the one I'm matching in setLastTimeUsed
is part of my wallets
state property.
|
||
return wallets.filter { listing in | ||
guard let lastTimeUsed = listing.lastTimeUsed else { | ||
assertionFailure("Shouldn't happen we stored wallet without `lastTimeUsed`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why we are storing without lastTimeUsed please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should never happen that we store it without lastTimeUsed
, so I've added this just as an extra check If we ever do.
<string>metamask</string> | ||
<string>trust</string> | ||
<string>safe</string> | ||
<string>zerion</string> | ||
<string>rainbow</string> | ||
<string>spot</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ignaciosantise how did you solve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dapps will have to modify their info.plist/android manifest manually to support the feature: https://docs.walletconnect.com/2.0/advanced/walletconnectmodal/about#for-ios
No description provided.