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: frontierWallet support #1041

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/short-follow-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@rainbow-me/rainbowkit': patch
---

Frontier Wallet Support

**Example usage**

```ts
import {
getDefaultWallets,
connectorsForWallets,
} from '@rainbow-me/rainbowkit';
import { frontierWallet } from '@rainbow-me/rainbowkit/wallets';
const { wallets } = getDefaultWallets({ appName, chains });
const connectors = connectorsForWallets([
...wallets,
{
groupName: 'Other',
wallets: [frontierWallet({ projectId, chains })],
},
]);
```
2 changes: 2 additions & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
argentWallet,
bitskiWallet,
dawnWallet,
frontierWallet,
imTokenWallet,
ledgerWallet,
mewWallet,
Expand Down Expand Up @@ -93,6 +94,7 @@ const connectors = connectorsForWallets([
argentWallet({ chains, projectId }),
bitskiWallet({ chains }),
dawnWallet({ chains }),
frontierWallet({ chains, projectId }),
imTokenWallet({ chains, projectId }),
ledgerWallet({ chains, projectId }),
mewWallet({ chains }),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */
import type { InjectedConnectorOptions } from '@wagmi/core';
import { InjectedConnector } from 'wagmi/connectors/injected';
import type { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { getWalletConnectUri } from '../../../utils/getWalletConnectUri';
import { isAndroid } from '../../../utils/isMobile';
import type { Wallet } from '../../Wallet';
import type {
WalletConnectConnectorOptions,
WalletConnectLegacyConnectorOptions,
} from '../../getWalletConnectConnector';
import { getWalletConnectConnector } from '../../getWalletConnectConnector';

declare global {
interface Window {
frontier: any;
}
}

export interface FrontierWalletLegacyOptions {
projectId?: string;
chains: Chain[];
walletConnectVersion: '1';
walletConnectOptions?: WalletConnectLegacyConnectorOptions;
}

export interface FrontierWalletOptions {
projectId: string;
chains: Chain[];
walletConnectVersion?: '2';
walletConnectOptions?: WalletConnectConnectorOptions;
}

export const frontierWallet = ({
chains,
projectId,
walletConnectOptions,
walletConnectVersion = '2',
...options
}: (FrontierWalletLegacyOptions | FrontierWalletOptions) &
InjectedConnectorOptions): Wallet => {
const isFrontierInjected =
typeof window !== 'undefined' &&
typeof window.frontier !== 'undefined' &&
window?.frontier?.ethereum?.isFrontier;
return {
id: 'frontier',
name: 'Frontier Wallet',
installed:
typeof window !== 'undefined' &&
typeof window.frontier !== 'undefined' &&
window?.frontier?.ethereum?.isFrontier
? true
: undefined,
iconUrl: async () => (await import('./frontierWallet.svg')).default,
iconBackground: '#CC703C',
downloadUrls: {
android:
'https://play.google.com/store/apps/details?id=com.frontierwallet',
ios: 'https://apps.apple.com/us/app/frontier-crypto-defi-wallet/id1482380988',
qrCode: 'https://www.frontier.xyz/download',
chrome:
'https://chrome.google.com/webstore/detail/frontier-wallet/kppfdiipphfccemcignhifpjkapfbihd',
browserExtension: 'https://www.frontier.xyz/download',
},
createConnector: () => {
const shouldUseWalletConnect = !isFrontierInjected;
const connector = shouldUseWalletConnect
? getWalletConnectConnector({
chains,
projectId,
options: walletConnectOptions,
version: walletConnectVersion,
})
: new InjectedConnector({ chains });
const getUri = async () => {
const uri = await getWalletConnectUri(connector, walletConnectVersion);
return isAndroid()
? `frontier://wc?uri=${encodeURIComponent(uri)}`
: uri;
};
return {
connector: new InjectedConnector({
chains,
options: {
getProvider: () => {
const getFront = (frontier?: any) =>
frontier?.ethereum ? frontier?.ethereum : undefined;
if (typeof window === 'undefined') return;
return getFront(window.frontier);
},
...options,
},
}),
mobile: {
getUri: shouldUseWalletConnect ? getUri : undefined,
},
qrCode: shouldUseWalletConnect
? {
getUri,
instructions: {
learnMoreUrl: 'https://help.frontier.xyz/en/',
steps: [
{
description:
'We recommend putting Frontier Wallet on your home screen for quicker access.',
step: 'install',
title: 'Open the Frontier Wallet app',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone.',
step: 'create',
title: 'Create or Import a Wallet',
},
{
description:
'After you scan, a connection prompt will appear for you to connect your wallet.',
step: 'scan',
title: 'Tap the scan button',
},
],
},
}
: undefined,
extension: {
instructions: {
learnMoreUrl:
'https://help.frontier.xyz/en/articles/6967236-setting-up-frontier-on-your-device',
steps: [
{
description:
'We recommend pinning Frontier Wallet to your taskbar for quicker access to your wallet.',
step: 'install',
title: 'Install the Frontier Wallet extension',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone.',
step: 'create',
title: 'Create or Import a Wallet',
},
{
description:
'Once you set up your wallet, click below to refresh the browser and load up the extension.',
step: 'refresh',
title: 'Refresh your browser',
},
],
},
},
};
},
};
};
2 changes: 2 additions & 0 deletions packages/rainbowkit/src/wallets/walletConnectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bitskiWallet } from './bitskiWallet/bitskiWallet';
import { braveWallet } from './braveWallet/braveWallet';
import { coinbaseWallet } from './coinbaseWallet/coinbaseWallet';
import { dawnWallet } from './dawnWallet/dawnWallet';
import { frontierWallet } from './frontierWallet/frontierWallet';
import { imTokenWallet } from './imTokenWallet/imTokenWallet';
import { injectedWallet } from './injectedWallet/injectedWallet';
import { ledgerWallet } from './ledgerWallet/ledgerWallet';
Expand All @@ -26,6 +27,7 @@ export {
braveWallet,
coinbaseWallet,
dawnWallet,
frontierWallet,
imTokenWallet,
injectedWallet,
ledgerWallet,
Expand Down
10 changes: 10 additions & 0 deletions site/data/docs/custom-wallet-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ dawnWallet(options: {
});
```

#### Frontier Wallet

```tsx
import { frontierWallet } from '@rainbow-me/rainbowkit/wallets';
frontierWallet(options: {
projectId: string;
chains: Chain[];
});
```

#### Ledger Live

```tsx
Expand Down