-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add token to wallet in mobile and avoid extension conflicts (#11092
) <!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the wallet functionality in the application. It replaces the previous synchronous token registration check with an asynchronous approach and introduces a more structured method for determining wallet compatibility and displaying wallet icons. ### Detailed summary - Renamed `canRegisterToken` to `checkWalletCanRegisterToken` for clarity. - Changed `checkWalletCanRegisterToken` to an asynchronous function using `Connector`. - Introduced `useWalletCanRegisterToken` for querying token registration support. - Created `useWalletIcon` for fetching and displaying wallet icons based on the connector. - Updated `AddToWalletButton` to use the new hooks for token registration and wallet icons. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
Showing
2 changed files
with
103 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
// Set of helper functions to facilitate wallet setup | ||
import { Connector } from 'wagmi' | ||
|
||
export const canRegisterToken = () => | ||
typeof window !== 'undefined' && | ||
// @ts-ignore | ||
!window?.ethereum?.isSafePal && | ||
(window?.ethereum?.isMetaMask || | ||
window?.ethereum?.isTrust || | ||
window?.ethereum?.isCoinbaseWallet || | ||
window?.ethereum?.isTokenPocket) | ||
export const checkWalletCanRegisterToken = async (connector: Connector) => { | ||
try { | ||
if (typeof connector.getProvider !== 'function') return false | ||
|
||
const provider = (await connector.getProvider()) as any | ||
|
||
return Boolean( | ||
provider && | ||
!provider.isSafePal && | ||
(provider.isMetaMask || provider.isTrust || provider.isCoinbaseWallet || provider.isTokenPocket), | ||
) | ||
} catch (error) { | ||
console.error(error, 'Error determining wallet token registration support') | ||
return false | ||
} | ||
} |