Skip to content

Commit

Permalink
feat: zerionWallet (#1108)
Browse files Browse the repository at this point in the history
* feat: zerionWallet

* fix: removed shimDisconnect option in favor of options passthrough

* fix: added window.zerionWallet check for zerionWallet

* fix: resolved zerion walletconnect uri typo
  • Loading branch information
DanielSinclair committed Mar 30, 2023
1 parent 7f669bd commit 2b4ede4
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .changeset/many-schools-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@rainbow-me/rainbowkit': patch
---

Zerion Support

**Example usage**

```ts
import {
getDefaultWallets,
connectorsForWallets,
} from '@rainbow-me/rainbowkit';
import { zerionWallet } from '@rainbow-me/rainbowkit/wallets';
const { wallets } = getDefaultWallets({ appName, chains });
const connectors = connectorsForWallets([
...wallets,
{
groupName: 'Other',
wallets: [zerionWallet({ chains })],
},
]);
```
2 changes: 2 additions & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
omniWallet,
tahoWallet,
trustWallet,
zerionWallet,
} from '@rainbow-me/rainbowkit/wallets';

import { SessionProvider, signOut } from 'next-auth/react';
Expand Down Expand Up @@ -123,6 +124,7 @@ const connectors = connectorsForWallets([
omniWallet({ chains }),
tahoWallet({ chains }),
trustWallet({ chains }),
zerionWallet({ chains }),
],
},
]);
Expand Down
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 @@ -15,6 +15,7 @@ import { safeWallet } from './safeWallet/safeWallet';
import { tahoWallet } from './tahoWallet/tahoWallet';
import { trustWallet } from './trustWallet/trustWallet';
import { walletConnectWallet } from './walletConnectWallet/walletConnectWallet';
import { zerionWallet } from './zerionWallet/zerionWallet';

export {
argentWallet,
Expand All @@ -34,4 +35,5 @@ export {
trustWallet,
okxWallet,
walletConnectWallet,
zerionWallet,
};
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,125 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */
import type { InjectedConnectorOptions } from '@wagmi/core/connectors/injected';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { isAndroid } from '../../../utils/isMobile';
import { Wallet } from '../../Wallet';
import { getWalletConnectConnector } from '../../getWalletConnectConnector';

export interface ZerionWalletOptions {
chains: Chain[];
}

export const zerionWallet = ({
chains,
...options
}: ZerionWalletOptions & InjectedConnectorOptions): Wallet => {
const isZerionInjected =
typeof window !== 'undefined' &&
((typeof window.ethereum !== 'undefined' && window.ethereum.isZerion) ||
// @ts-expect-error
typeof window.zerionWallet !== 'undefined');

const shouldUseWalletConnect = !isZerionInjected;

return {
id: 'zerion',
name: 'Zerion',
iconUrl: async () => (await import('./zerionWallet.svg')).default,
iconAccent: '#2962ef',
iconBackground: '#fff',
installed: !shouldUseWalletConnect ? isZerionInjected : undefined,
downloadUrls: {
browserExtension:
'https://chrome.google.com/webstore/detail/klghhnkeealcohjjanjjdaeeggmfmlpl',
android:
'https://play.google.com/store/apps/details?id=io.zerion.android',
ios: 'https://apps.apple.com/app/apple-store/id1456732565',
qrCode: 'https://link.zerion.io/pt3gdRP0njb',
},
createConnector: () => {
const connector = shouldUseWalletConnect
? getWalletConnectConnector({ chains })
: new InjectedConnector({
chains,
options: {
getProvider: () =>
typeof window !== 'undefined'
? // @ts-expect-error
window.zerionWallet || window.ethereum
: undefined,
...options,
},
});

const getUri = async () => {
const { uri } = (await connector.getProvider()).connector;

return isAndroid()
? uri
: `https://wallet.zerion.io/wc?uri=${encodeURIComponent(uri)}`;
};

return {
connector,
mobile: {
getUri: shouldUseWalletConnect ? getUri : undefined,
},
qrCode: shouldUseWalletConnect
? {
getUri,
instructions: {
learnMoreUrl:
'https://zerion.io/blog/announcing-the-zerion-smart-wallet/',
steps: [
{
description:
'We recommend putting Zerion on your home screen for quicker access.',
step: 'install',
title: 'Open the Zerion 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.zerion.io/en/',
steps: [
{
description:
'We recommend pinning Zerion to your taskbar for quicker access to your wallet.',
step: 'install',
title: 'Install the Zerion 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',
},
],
},
},
};
},
};
};
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 @@ -255,6 +255,16 @@ trustWallet(options: {
});
```
#### Zerion
```tsx
import { zerionWallet } from '@rainbow-me/rainbowkit/wallets';

zerionWallet(options: {
chains: Chain[];
});
```
### Examples
#### Ordering
Expand Down

2 comments on commit 2b4ede4

@vercel
Copy link

@vercel vercel bot commented on 2b4ede4 Mar 30, 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 2b4ede4 Mar 30, 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.