Skip to content

Commit

Permalink
feat: subWallet support (#1564)
Browse files Browse the repository at this point in the history
* feat: add SubWallet wallet

feat: update change set

feat: update custom-wallet-list

feat: add WalletConnect and Mobile for SubWallet

feat: fix wrong logo path

* fix: changeset

* fix: rebase

* fix: i18n

* fix: ordering

* fix: i18n key

* fix: changeset

* fix: i18n keys

---------

Co-authored-by: S2kael <laiducminh1002@gmail.com>
  • Loading branch information
DanielSinclair and S2kael committed Oct 23, 2023
1 parent b0022ae commit efb8566
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .changeset/empty-bottles-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@rainbow-me/rainbowkit': patch
---

SubWallet Support

**Example usage**

```ts
import {
getDefaultWallets,
connectorsForWallets,
} from '@rainbow-me/rainbowkit';
import { subWallet } from '@rainbow-me/rainbowkit/wallets';
const { wallets } = getDefaultWallets({ appName, chains, projectId });
const connectors = connectorsForWallets([
...wallets,
{
groupName: 'Other',
wallets: [subWallet({ chains, projectId })],
},
]);
```
2 changes: 2 additions & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
rabbyWallet,
safeheronWallet,
safepalWallet,
subWallet,
tahoWallet,
talismanWallet,
tokenPocketWallet,
Expand Down Expand Up @@ -135,6 +136,7 @@ const connectors = connectorsForWallets([
rabbyWallet({ chains }),
safeheronWallet({ chains }),
safepalWallet({ chains, projectId }),
subWallet({ chains, projectId }),
tahoWallet({ chains }),
talismanWallet({ chains }),
tokenPocketWallet({ chains, projectId }),
Expand Down
31 changes: 31 additions & 0 deletions packages/rainbowkit/src/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,37 @@
"description": "Once you set up your wallet, click below to refresh the browser and load up the extension."
}
}
},

"subwallet": {
"extension": {
"step1": {
"title": "Install the SubWallet extension",
"description": "We recommend pinning SubWallet to your taskbar for quicker access to your wallet."
},
"step2": {
"title": "Create or Import a Wallet",
"description": "Be sure to back up your wallet using a secure method. Never share your recovery phrase with anyone."
},
"step3": {
"title": "Refresh your browser",
"description": "Once you set up your wallet, click below to refresh the browser and load up the extension."
}
},
"qr_code": {
"step1": {
"title": "Open the SubWallet app",
"description": "We recommend putting SubWallet on your home screen for quicker access."
},
"step2": {
"title": "Create or Import a Wallet",
"description": "Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone."
},
"step3": {
"title": "Tap the scan button",
"description": "After you scan, a connection prompt will appear for you to connect your wallet."
}
}
}
}
}
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 @@ -26,6 +26,7 @@ import { rainbowWallet } from './rainbowWallet/rainbowWallet';
import { safeWallet } from './safeWallet/safeWallet';
import { safeheronWallet } from './safeheronWallet/safeheronWallet';
import { safepalWallet } from './safepalWallet/safepalWallet';
import { subWallet } from './subWallet/subWallet';
import { tahoWallet } from './tahoWallet/tahoWallet';
import { talismanWallet } from './talismanWallet/talismanWallet';
import { tokenPocketWallet } from './tokenPocketWallet/tokenPocketWallet';
Expand Down Expand Up @@ -66,6 +67,7 @@ export {
safeWallet,
safeheronWallet,
safepalWallet,
subWallet,
tahoWallet,
talismanWallet,
tokenPocketWallet,
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,152 @@
import type { InjectedConnectorOptions } from '@wagmi/core/connectors/injected';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { getWalletConnectUri } from '../../../utils/getWalletConnectUri';
import { InstructionStepName, Wallet } from '../../Wallet';
import {
WalletConnectConnectorOptions,
getWalletConnectConnector,
} from '../../getWalletConnectConnector';

declare global {
interface Window {
SubWallet: Window['ethereum'];
}
}

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

const getSubWalletInjectedProvider = (): Window['ethereum'] => {
if (typeof window === 'undefined') return;
return window.SubWallet;
};

export const subWallet = ({
chains,
projectId,
walletConnectOptions,
walletConnectVersion = '2',
...options
}: SubWalletOptions & InjectedConnectorOptions): Wallet => {
const isSubWalletInjected = Boolean(getSubWalletInjectedProvider());
const shouldUseWalletConnect = !isSubWalletInjected;

return {
id: 'subwallet',
name: 'SubWallet',
iconUrl: async () => (await import('./subWallet.svg')).default,
iconBackground: '#fff',
installed: isSubWalletInjected || undefined,
downloadUrls: {
browserExtension: 'https://www.subwallet.app/download',
chrome:
'https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn',
firefox: 'https://addons.mozilla.org/en-US/firefox/addon/subwallet/',
edge: 'https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn',
mobile: 'https://www.subwallet.app/download',
android:
'https://play.google.com/store/apps/details?id=app.subwallet.mobile',
ios: 'https://apps.apple.com/us/app/subwallet-polkadot-wallet/id1633050285',
qrCode: 'https://www.subwallet.app/download',
},
createConnector: () => {
const connector = shouldUseWalletConnect
? getWalletConnectConnector({
projectId,
chains,
version: walletConnectVersion,
options: walletConnectOptions,
})
: new InjectedConnector({
chains,
options: {
getProvider: getSubWalletInjectedProvider,
...options,
},
});

const getUriMobile = async () => {
const uri = await getWalletConnectUri(connector, walletConnectVersion);

return `subwallet://wc?uri=${encodeURIComponent(uri)}`;
};

const getUriQR = async () => {
return await getWalletConnectUri(connector, walletConnectVersion);
};

const mobileConnector = {
getUri: shouldUseWalletConnect ? getUriMobile : undefined,
};

let qrConnector = undefined;

if (shouldUseWalletConnect) {
qrConnector = {
getUri: getUriQR,
instructions: {
learnMoreUrl: 'https://www.subwallet.app/',
steps: [
{
description:
'wallet_connectors.subwallet.qr_code.step1.description',
step: 'install' as InstructionStepName,
title: 'wallet_connectors.subwallet.qr_code.step1.title',
},
{
description:
'wallet_connectors.subwallet.qr_code.step2.description',
step: 'create' as InstructionStepName,
title: 'wallet_connectors.subwallet.qr_code.step2.title',
},
{
description:
'wallet_connectors.subwallet.qr_code.step3.description',
step: 'scan' as InstructionStepName,
title: 'wallet_connectors.subwallet.qr_code.step3.title',
},
],
},
};
}

const extensionConnector = {
instructions: {
learnMoreUrl: 'https://www.subwallet.app/',
steps: [
{
description:
'wallet_connectors.subwallet.extension.step1.description',
step: 'install' as InstructionStepName,
title: 'wallet_connectors.subwallet.extension.step1.title',
},
{
description:
'wallet_connectors.subwallet.extension.step2.description',
step: 'create' as InstructionStepName,
title: 'wallet_connectors.subwallet.extension.step2.title',
},
{
description:
'wallet_connectors.subwallet.extension.step3.description',
step: 'refresh' as InstructionStepName,
title: 'wallet_connectors.subwallet.extension.step3.title',
},
],
},
};

return {
connector,
mobile: mobileConnector,
qrCode: qrConnector,
extension: extensionConnector,
};
},
};
};
11 changes: 11 additions & 0 deletions site/data/docs/custom-wallet-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ safepalWallet(options: {
});
```

#### SubWallet

```tsx
import { subWallet } from '@rainbow-me/rainbowkit/wallets';

subWallet(options: {
chains: Chain[];
projectId: string;
});
```

#### Taho

```tsx
Expand Down

2 comments on commit efb8566

@vercel
Copy link

@vercel vercel bot commented on efb8566 Oct 23, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on efb8566 Oct 23, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.