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

[WCM] Detect installed wallets #991

Merged
merged 3 commits into from
Aug 24, 2023
Merged

Conversation

radeknovis
Copy link
Contributor

No description provided.

@radeknovis radeknovis temporarily deployed to internal July 27, 2023 16:12 — with GitHub Actions Inactive
<string>zerion</string>
<string>rainbow</string>
<string>spot</string>
</array>
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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 😁

Copy link
Contributor Author

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.

@radeknovis radeknovis temporarily deployed to internal July 28, 2023 10:52 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 11, 2023 11:40 — with GitHub Actions Inactive
@asi90sp asi90sp mentioned this pull request Aug 13, 2023
@radeknovis radeknovis temporarily deployed to internal August 18, 2023 09:50 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 18, 2023 09:56 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 18, 2023 11:41 — with GitHub Actions Inactive
input.sorted { lhs, rhs in
guard let lhsLastTimeUsed = lhs.lastTimeUsed else {
func sortByOrder() -> [Listing] {
self.sorted {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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`")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@radeknovis radeknovis temporarily deployed to internal August 21, 2023 11:13 — with GitHub Actions Inactive
Comment on lines +7 to +12
<string>metamask</string>
<string>trust</string>
<string>safe</string>
<string>zerion</string>
<string>rainbow</string>
<string>spot</string>
Copy link
Member

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?

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

@radeknovis radeknovis temporarily deployed to internal August 22, 2023 08:42 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 22, 2023 15:25 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 22, 2023 15:34 — with GitHub Actions Inactive
@radeknovis radeknovis temporarily deployed to internal August 24, 2023 09:09 — with GitHub Actions Inactive
@radeknovis radeknovis merged commit ec16440 into develop Aug 24, 2023
8 checks passed
@radeknovis radeknovis deleted the feat/wcm/installed-wallets branch August 24, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants