Skip to content

Commit

Permalink
feat: safe connector (#1028)
Browse files Browse the repository at this point in the history
* Added Safe (Gnosis) connector.

* fix: amended default wallet list order

* fix: linting issues

* fix: renamed safe icon

* fix: removed gnosis from name

* fix: added Safe App manifest

* fix: added manifest iconPath and favicon

* fix: updated safeWallet logo

* chore: added changeset

* fix: cleaned up safe connector options and installed logic

* fix: removed shimDisconnect in favor of options passthrough

---------

Co-authored-by: Stas SUȘCOV <stas@nerd.ro>
  • Loading branch information
DanielSinclair and stas committed Mar 23, 2023
1 parent 021c4e0 commit 9b93f56
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-camels-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rainbow-me/rainbowkit': patch
---

Added `safeWallet` connector to support Safe Apps. dApps that rely on `getDefaultWallets` will adopt this behavior automatically. dApps that rely on the Custom Wallet List should add `safeWallet` alongside `injectedWallet`.
1 change: 1 addition & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export default function App(appProps: AppProps) {
<>
<Head>
<title>RainbowKit Example</title>
<link href="/favicon.ico" rel="icon" />
</Head>
<SessionProvider refetchInterval={0} session={appProps.pageProps.session}>
<WagmiConfig client={wagmiClient}>
Expand Down
Binary file added packages/example/public/favicon.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions packages/example/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "RainbowKit Example",
"description": "Test dApp deployment of RainbowKit",
"iconPath": "rainbow.svg"
}
1 change: 1 addition & 0 deletions packages/example/public/rainbow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/rainbowkit/src/wallets/getDefaultWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { coinbaseWallet } from './walletConnectors/coinbaseWallet/coinbaseWallet
import { injectedWallet } from './walletConnectors/injectedWallet/injectedWallet';
import { metaMaskWallet } from './walletConnectors/metaMaskWallet/metaMaskWallet';
import { rainbowWallet } from './walletConnectors/rainbowWallet/rainbowWallet';
import { safeWallet } from './walletConnectors/safeWallet/safeWallet';
import { walletConnectWallet } from './walletConnectors/walletConnectWallet/walletConnectWallet';

export const getDefaultWallets = ({
Expand All @@ -23,6 +24,7 @@ export const getDefaultWallets = ({
groupName: 'Popular',
wallets: [
injectedWallet({ chains }),
safeWallet({ chains }),
rainbowWallet({ chains }),
coinbaseWallet({ appName, chains }),
metaMaskWallet({ 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 @@ -9,6 +9,7 @@ import { metaMaskWallet } from './metaMaskWallet/metaMaskWallet';
import { mewWallet } from './mewWallet/mewWallet';
import { omniWallet } from './omniWallet/omniWallet';
import { rainbowWallet } from './rainbowWallet/rainbowWallet';
import { safeWallet } from './safeWallet/safeWallet';
import { trustWallet } from './trustWallet/trustWallet';
import { walletConnectWallet } from './walletConnectWallet/walletConnectWallet';

Expand All @@ -24,6 +25,7 @@ export {
mewWallet,
omniWallet,
rainbowWallet,
safeWallet,
trustWallet,
walletConnectWallet,
};
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,33 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */
import type { SafeConnectorOptions } from 'wagmi/connectors/safe';
import { SafeConnector } from 'wagmi/connectors/safe';
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { Wallet } from '../../Wallet';

export interface SafeWalletOptions {
chains: Chain[];
}

export const safeWallet = ({
chains,
...options
}: SafeWalletOptions & SafeConnectorOptions): Wallet => ({
id: 'safe',
name: 'Safe',
iconAccent: '#12ff80',
iconBackground: '#fff',
iconUrl: async () => (await import('./safeWallet.svg')).default,
installed:
// Only allowed in iframe context
// borrowed from wagmi safe connector
!(typeof window === 'undefined') && window?.parent !== window,
downloadUrls: {
// We're opting not to provide a download prompt if Safe isn't the current
// browser since it's unlikely to be a desired behavior for users. It's
// more of a convenience for users who are already using Brave rather than
// an explicit wallet choice for users coming from other browsers.
},
createConnector: () => ({
connector: new SafeConnector({ chains, options }),
}),
});

2 comments on commit 9b93f56

@vercel
Copy link

@vercel vercel bot commented on 9b93f56 Mar 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 9b93f56 Mar 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.