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

feat: add imToken wallet #3820

Open
wants to merge 1 commit into
base: stage
Choose a base branch
from
Open

feat: add imToken wallet #3820

wants to merge 1 commit into from

Conversation

xwartz
Copy link

@xwartz xwartz commented Sep 3, 2024

What is the purpose of the change:

This PR introduces support for the imToken wallet in the Osmosis Zone web interface, allowing users to connect their imToken wallets and interact with the Osmosis decentralized exchange (DEX) and other applications built on the Osmosis blockchain.

By integrating imToken wallet support, we aim to:

  • Expand wallet options: Provide users with more choices when selecting a wallet to use with the Osmosis Zone web app, improving accessibility and inclusivity.
  • Enhance user experience: Make it easier for imToken users to participate in the Osmosis ecosystem by enabling seamless wallet connection and interaction with the web interface.
  • Align with Osmosis' vision: Support Osmosis' goal of being a user-friendly and widely accessible DEX by ensuring compatibility with popular wallet options like imToken.

Linear Task

N/A

Brief Changelog

  • Added a new wallet adapter for imToken, following the existing structure of wallet integrations in the Osmosis Zone web interface.

Testing and Verifying

This change has been tested locally by rebuilding the website and verified content and links are expected

Copy link

vercel bot commented Sep 3, 2024

@xwartz is attempting to deploy a commit to the OsmoLabs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The pull request introduces several changes across multiple files to enhance wallet functionality within the application. Key updates include the addition of imTokenWalletInfo to the wallet list, type annotations for the chainId parameter in various wallet support methods, and modifications to the wallet selection logic for mobile users. These changes aim to improve type safety, consistency, and wallet selection capabilities, particularly for mobile environments.

Changes

Files Change Summary
packages/web/config/generate-cosmos-kit-wallet-list.ts Added imTokenWalletInfo to CosmosKitWalletList, enhancing the list of available wallets. Minor formatting change in generateCosmosKitWalletList function.
packages/web/config/wallet-registry.ts Updated method signatures for supportsChain in several wallet configurations to explicitly type chainId as a string. Added IMTokenWallet configuration with its own supportsChain method.
packages/web/modals/wallet-select/use-selectable-wallets.ts Introduced a conditional block in useSelectableWallets to handle the imToken wallet specifically for mobile web mode. Adjusted return statements for formatting consistency. No changes to exported or public entity declarations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WalletSelection
    participant WalletRegistry

    User->>WalletSelection: Initiate wallet selection
    WalletSelection->>WalletRegistry: Retrieve available wallets
    WalletRegistry-->>WalletSelection: Return wallet list
    WalletSelection->>User: Display wallet options
    User->>WalletSelection: Select imToken wallet
    WalletSelection->>WalletRegistry: Check if imToken supports chain
    WalletRegistry-->>WalletSelection: Return support status
    WalletSelection->>User: Confirm selection
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3205843 and bdd6f76.

⛔ Files ignored due to path filters (3)
  • packages/web/package.json is excluded by !**/*.json
  • packages/web/public/wallets/imtoken.svg is excluded by !**/*.svg, !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock, !**/*.lock
📒 Files selected for processing (3)
  • packages/web/config/generate-cosmos-kit-wallet-list.ts (3 hunks)
  • packages/web/config/wallet-registry.ts (7 hunks)
  • packages/web/modals/wallet-select/use-selectable-wallets.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/web/config/generate-cosmos-kit-wallet-list.ts
  • packages/web/config/wallet-registry.ts
  • packages/web/modals/wallet-select/use-selectable-wallets.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (6)
packages/web/config/generate-cosmos-kit-wallet-list.ts (1)

42-42: LGTM: imTokenWalletInfo added to CosmosKitWalletList.

The imTokenWalletInfo has been correctly added to the CosmosKitWalletList array, consistent with how other wallets are included. This change directly contributes to the PR objective of integrating the imToken wallet into the Osmosis Zone web interface.

Consider the order of wallets in the list, as it might affect the presentation to users. You may want to discuss with the team if there's a preferred order for displaying wallet options.

packages/web/config/wallet-registry.ts (3)

165-166: LGTM: Type annotations added and formatting improved

The changes improve type safety by adding type annotations for chainId, retryCount, and the getKey method. The formatting changes enhance readability. The logic remains unchanged, which is good.

Consider using a more descriptive name for the okxWallet.keplr property, as it might be confusing to see a Keplr-related property in the OKX wallet implementation. If this is intentional due to some compatibility layer, consider adding a comment explaining this.

Also applies to: 169-170, 175-176, 178-178, 185-185, 202-202, 204-204, 207-207, 211-211, 218-218, 221-221


284-285: LGTM: Type annotations added and formatting improved

The changes improve type safety by adding type annotations for chainId and the getKey method. The formatting changes enhance readability. The logic remains unchanged, which is good.

Similar to the OKX wallet, consider using a more descriptive name for the xfiWallet.keplr property, as it might be confusing to see a Keplr-related property in the XDEFI wallet implementation. If this is intentional due to some compatibility layer, consider adding a comment explaining this.

Also applies to: 288-289, 291-291, 296-296


321-322: LGTM: Type annotations added and logic slightly improved

The changes improve type safety by adding type annotations for chainId and the getChainInfosWithoutEndpoints method. The logic has been slightly improved by using some instead of find, which is more efficient for this use case.

Consider using a more descriptive name for the stationWallet.keplr property, as it might be confusing to see a Keplr-related property in the Station wallet implementation. If this is intentional due to some compatibility layer, consider adding a comment explaining this.

Also applies to: 325-326, 328-328, 330-331

packages/web/modals/wallet-select/use-selectable-wallets.ts (2)

85-85: Consider renaming _window to avoid confusion

Using the variable name _window might cause confusion, as it is similar to the global window object. To improve code clarity, consider renaming it to something more descriptive.

Suggested change:

- const _window = window as Record<string, any>
+ const windowRef = window as Record<string, any>

105-109: Enhance clarity of the code comment

The comment could be rephrased for better readability and to accurately convey the intended meaning.

Suggested rephrasing:

/**
- * If on mobile and `imToken` is in `window`, it means that the user enters
- * the frontend from imToken's app in app browser. So, there is no need
- * to use wallet connect, as it resembles the extension's usage.
+ * When `imToken` is present in `window` on a mobile device, it indicates that
+ * the user is accessing the frontend from the imToken in-app browser.
+ * Therefore, there is no need to use WalletConnect, as it functions like an extension.
 */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca647f1 and c295f22.

Files ignored due to path filters (3)
  • packages/web/package.json is excluded by !**/*.json
  • packages/web/public/wallets/imtoken.svg is excluded by !**/*.svg, !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock, !**/*.lock
Files selected for processing (3)
  • packages/web/config/generate-cosmos-kit-wallet-list.ts (3 hunks)
  • packages/web/config/wallet-registry.ts (9 hunks)
  • packages/web/modals/wallet-select/use-selectable-wallets.ts (4 hunks)
Additional context used
Biome
packages/web/modals/wallet-select/use-selectable-wallets.ts

[error] 148-148: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

Additional comments not posted (8)
packages/web/config/generate-cosmos-kit-wallet-list.ts (2)

8-8: LGTM: Import statement for imTokenWalletInfo added correctly.

The import statement for imTokenWalletInfo from @cosmos-kit/imtoken-extension has been added correctly, following the same pattern as other wallet imports in the file. This addition aligns with the PR objective of introducing support for the imToken wallet.


Line range hint 1-141: Summary: imToken wallet support successfully added.

The changes in this file successfully introduce support for the imToken wallet by importing the necessary information and adding it to the CosmosKitWalletList. These modifications are consistent with the existing code structure and align well with the PR objectives.

The implementation:

  1. Imports the imTokenWalletInfo from the appropriate package.
  2. Adds imTokenWalletInfo to the CosmosKitWalletList array.

These changes will allow the imToken wallet to be included in the generated TypeScript file containing approved wallets for Cosmos Kit, thereby enabling users to connect their imToken wallets to the Osmosis Zone web interface.

packages/web/config/wallet-registry.ts (5)

29-29: LGTM: Type annotation added and coding style improved

The changes improve type safety by adding a type annotation for chainId and maintain consistency in coding style by removing the semicolon. The logic remains unchanged, which is good.

Also applies to: 59-59


81-81: LGTM: Type annotation added and coding style improved

Similar to the previous change, this update adds a type annotation for chainId and removes the semicolon, improving type safety and maintaining consistent coding style. The logic remains intact.

Also applies to: 150-150


265-265: LGTM: Type annotation added and coding style improved

The changes improve type safety by adding a type annotation for chainId and maintain consistency in coding style by removing the semicolon. The logic remains unchanged, which is good.

Also applies to: 270-271


Line range hint 1-351: Overall assessment: Good improvements with minor suggestions

The changes in this file significantly improve type safety and consistency across various wallet configurations. The addition of the IMTokenWallet aligns with the PR objectives to introduce support for the imToken wallet.

While the changes are generally good, there are a few minor suggestions for improvements:

  1. Consider adding explanatory comments for Keplr-related properties in non-Keplr wallet implementations.
  2. Ensure the IMTokenWallet configuration is complete and consistent with other wallet configurations.
  3. Verify the imToken integration using the provided script.

These minor adjustments will further enhance the code quality and maintainability.


338-350: LGTM: IMTokenWallet support added

The addition of IMTokenWallet configuration aligns with the PR objectives and follows the structure of other wallet configurations in the registry. The implementation includes necessary properties and methods, including a supportsChain method with proper type annotations.

  1. Consider renaming the cdcAvailableChains variable to imTokenAvailableChains for clarity.
  2. The mobileDisabled property is set to false, which differs from some other wallets. Ensure this is intentional and aligns with imToken's mobile support.
  3. Consider adding stakeUrl and governanceUrl properties if imToken supports these features, to maintain consistency with other wallet configurations.

To ensure the imToken wallet integration is complete, please run the following verification script:

Verification successful

Verified: IMTokenWallet integration confirmed

All verification steps have successfully validated the IMTokenWallet configuration:

  • Import Statement: IMTokenWallet is properly imported from @cosmos-kit/imtoken-extension.
  • Logo File: /wallets/imtoken.svg exists and is correctly referenced.
  • Wallet Registration: IMTokenWallet is included in the wallet lists and selectors.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify imToken wallet integration

# Test 1: Check if imToken wallet is properly imported
rg --type typescript 'import.*IMTokenWallet.*from.*@cosmos-kit/imtoken-extension'

# Test 2: Verify imToken logo file exists
test -f "$(fd --type file 'imtoken.svg' | head -n 1)" && echo "imToken logo found" || echo "imToken logo not found"

# Test 3: Check if imToken wallet is added to any wallet lists or selectors
rg --type typescript 'imtoken|IMTokenWallet'

Length of output: 340


Script:

#!/bin/bash
# Description: Re-verify imToken wallet integration without using unsupported --type flag

# Test 1: Check if imToken wallet is properly imported
rg --glob '*.ts' --glob '*.tsx' 'import.*IMTokenWallet.*from.*@cosmos-kit/imtoken-extension'

# Test 3: Check if imToken wallet is added to any wallet lists or selectors
rg --glob '*.ts' --glob '*.tsx' 'imtoken|IMTokenWallet'

Length of output: 549

packages/web/modals/wallet-select/use-selectable-wallets.ts (1)

111-112: Incorrect property access in if condition

In the condition checking for imToken, the property access might be incorrect. You're accessing _window?.cosmos?.mode, but it should likely be _window?.imToken?.cosmos?.mode to correctly check the cosmos.mode within the imToken object.

Apply this diff to correct the property access:

if (
  _window?.imToken &&
- _window?.cosmos?.mode === mobileWebModeName
+ _window?.imToken?.cosmos?.mode === mobileWebModeName
)

Likely invalid or redundant comment.

Copy link

vercel bot commented Sep 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend ❌ Failed (Inspect) Oct 8, 2024 3:14am

@MaxMillington
Copy link
Collaborator

Screenshot 2024-09-27 at 7 59 54 AM

@xwartz looks like we have some linting errors preventing the build from passing. Can you fix, rebase, and repush a passing build? Then we can get it reviewed

@xwartz
Copy link
Author

xwartz commented Sep 30, 2024

Screenshot 2024-09-27 at 7 59 54 AM @xwartz looks like we have some linting errors preventing the build from passing. Can you fix, rebase, and repush a passing build? Then we can get it reviewed

The build should now pass successfully. I would appreciate it if you could take a moment to review the changes when you have time.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
packages/web/modals/wallet-select/use-selectable-wallets.ts (1)

105-118: LGTM: Successfully added imToken wallet support

The new conditional block effectively adds support for the imToken wallet in mobile web mode, aligning perfectly with the PR objectives. The implementation follows the established pattern for other mobile wallets, ensuring consistency in the codebase.

For even better consistency, consider extracting the repeated pattern of filtering and mapping wallets into a separate function. This would reduce code duplication across different wallet checks.

Here's a suggested refactoring:

const filterAndMapWallet = (walletName: string) => 
  array
    .filter((wallet) => wallet.name === walletName)
    .map((wallet) => ({ ...wallet, mobileDisabled: false }));

// Then use it like this:
if (_window?.imToken && _window?.cosmos?.mode === mobileWebModeName) {
  return filterAndMapWallet(AvailableCosmosWallets.imToken);
}

This refactoring can be applied to other similar blocks in the function as well.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c295f22 and 3205843.

⛔ Files ignored due to path filters (3)
  • packages/web/package.json is excluded by !**/*.json
  • packages/web/public/wallets/imtoken.svg is excluded by !**/*.svg, !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock, !**/*.lock
📒 Files selected for processing (3)
  • packages/web/config/generate-cosmos-kit-wallet-list.ts (3 hunks)
  • packages/web/config/wallet-registry.ts (9 hunks)
  • packages/web/modals/wallet-select/use-selectable-wallets.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/web/config/generate-cosmos-kit-wallet-list.ts
  • packages/web/config/wallet-registry.ts
🧰 Additional context used
🪛 Biome
packages/web/modals/wallet-select/use-selectable-wallets.ts

[error] 148-148: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (2)
packages/web/modals/wallet-select/use-selectable-wallets.ts (2)

82-86: LGTM: Improved code readability

The removal of the semicolon and the introduction of new variables _window and mobileWebModeName enhance code readability and maintainability. These changes align well with the PR objectives of improving wallet selection for mobile users.


129-129: LGTM: Minor style improvements

The removal of semicolons after the closing parentheses on lines 129 and 142 is a minor style improvement that enhances code consistency.

Also applies to: 142-142

}

/**
* If user is in a normal mobile browser, show only wallet connect
*/
return wallet.name.endsWith("mobile") ? [...acc, wallet] : acc;
return wallet.name.endsWith("mobile") ? [...acc, wallet] : acc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Performance: Avoid spread syntax in .reduce

The use of spread syntax within the .reduce accumulator can lead to O(n^2) time complexity, which may negatively impact performance, especially for larger arrays. This issue was pointed out in a previous review and should be addressed.

Consider refactoring the code as follows to improve performance:

return wallet.name.endsWith("mobile") ? (acc.push(wallet), acc) : acc;

This change uses the comma operator to push the wallet to the accumulator and return it in a single expression, maintaining the concise nature of the original code while avoiding the spread syntax.

🧰 Tools
🪛 Biome

[error] 148-148: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

@MaxMillington
Copy link
Collaborator

@xwartz Looks like we are getting a type error on the build
Screenshot 2024-09-30 at 8 46 20 AM

@xwartz
Copy link
Author

xwartz commented Oct 7, 2024

@xwartz Looks like we are getting a type error on the build

The code has been updated, could you please take a moment to review the changes?

@CryptoAssassin1
Copy link
Member

@xwartz can you please share the link of desktop extension.

@xwartz
Copy link
Author

xwartz commented Oct 8, 2024

@xwartz can you please share the link of desktop extension.

I would like to clarify that imToken is primarily a mobile application and currently does not offer a desktop extension or version. Users can connect their imToken wallet via the mobile app, which supports various functionalities for interacting with dApps.

@CryptoAssassin1
Copy link
Member

@xwartz just to confirm this is the correct link im mobile app?
https://token.im/download

@xwartz
Copy link
Author

xwartz commented Oct 8, 2024

@xwartz just to confirm this is the correct link im mobile app? token.im/download

yes

@CryptoAssassin1
Copy link
Member

@xwartz not seeing imToken wallet option.Screenshot_2024-10-08-20-37-29-17_aef62f4795c04433e6e8a178b261b187.jpg

@xwartz
Copy link
Author

xwartz commented Oct 9, 2024

@xwartz not seeing imToken wallet option.

Hey, could you please share the URL where you are trying to see the imToken wallet option? This will help me understand the context better.

@CryptoAssassin1
Copy link
Member

I downloaded the imToken wallet and used the in app browser and used this PR preview link.

@CryptoAssassin1
Copy link
Member

@xwartz
Copy link
Author

xwartz commented Oct 10, 2024

I downloaded the imToken wallet and used the in app browser and used this PR preview link.

I apologize for the confusion. Currently, the version that supports the Cosmos provider (v2.16.0) has not yet been released and is still in the testing phase. Once it is officially launched, the imToken wallet option will be available.

Thank you for your understanding, and please let me know if you have any other questions!

imToken.mp4

@MaxMillington
Copy link
Collaborator

@xwartz sounds like we should await it's launch, so that we can test before merging?

@xwartz
Copy link
Author

xwartz commented Dec 26, 2024

@xwartz sounds like we should await it's launch, so that we can test before merging?

The changes have already been deployed to production and are ready for testing. You can proceed with the testing now. Let me know if you need any assistance or if you find any issues that need to be addressed.

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.

4 participants