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: add preference property to coinbaseWallet #2017

Merged
merged 8 commits into from
May 30, 2024
34 changes: 34 additions & 0 deletions .changeset/little-adults-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@rainbow-me/rainbowkit": patch
"example": patch
---

Added `preference` property to `coinbaseWallet`. You can now enable coinbase smart wallet feature like so:

```tsx
import { getDefaultConfig } from '@rainbow-me/rainbowkit';
import { coinbaseWallet } from '@rainbow-me/rainbowkit/wallets';
import {
arbitrum,
base,
mainnet,
optimism,
polygon,
sepolia,
} from 'wagmi/chains';

// Enable coinbase smart wallet feature
coinbaseWallet.preference = 'smartWalletOnly';

export const config = getDefaultConfig({
appName: 'RainbowKit demo',
projectId: 'YOUR_PROJECT_ID',
wallets: [
{
groupName: 'Popular',
wallets: [coinbaseWallet],
},
],
chains: [mainnet],
});
```
20 changes: 16 additions & 4 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
RainbowKitProvider,
darkTheme,
getDefaultConfig,
getDefaultWallets,
lightTheme,
midnightTheme,
} from '@rainbow-me/rainbowkit';
Expand All @@ -27,6 +26,7 @@ import {
bybitWallet,
clvWallet,
coin98Wallet,
coinbaseWallet,
compassWallet,
coreWallet,
dawnWallet,
Expand All @@ -42,6 +42,7 @@ import {
kresusWallet,
ledgerWallet,
magicEdenWallet,
metaMaskWallet,
mewWallet,
nestWallet,
oktoWallet,
Expand All @@ -51,6 +52,7 @@ import {
oneKeyWallet,
phantomWallet,
rabbyWallet,
rainbowWallet,
ramperWallet,
roninWallet,
safeheronWallet,
Expand All @@ -62,6 +64,7 @@ import {
tokenaryWallet,
trustWallet,
uniswapWallet,
walletConnectWallet,
xdefiWallet,
zealWallet,
zerionWallet,
Expand Down Expand Up @@ -108,8 +111,6 @@ const RAINBOW_TERMS = 'https://rainbow.me/terms-of-use';
const projectId =
process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? 'YOUR_PROJECT_ID';

const { wallets } = getDefaultWallets();

const avalanche = {
id: 43_114,
name: 'Avalanche',
Expand Down Expand Up @@ -146,6 +147,9 @@ const sei = {
contracts: {},
} as const satisfies Chain;

// Enable coinbase smart wallet feature
coinbaseWallet.preference = 'smartWalletOnly';

magiziz marked this conversation as resolved.
Show resolved Hide resolved
const config = getDefaultConfig({
appName: 'RainbowKit Demo',
projectId,
Expand Down Expand Up @@ -181,7 +185,15 @@ const config = getDefaultConfig({
: []),
],
wallets: [
...wallets,
{
groupName: 'Popular',
wallets: [
rainbowWallet,
coinbaseWallet,
metaMaskWallet,
walletConnectWallet,
],
},
{
groupName: 'Other',
wallets: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { CreateConnectorFn, createConnector } from 'wagmi';
import { coinbaseWallet as coinbaseConnector } from 'wagmi/connectors';
import {
CoinbaseWalletParameters,
coinbaseWallet as coinbaseConnector,
} from 'wagmi/connectors';
import { isIOS } from '../../../utils/isMobile';
import { Wallet, WalletDetailsParams } from '../../Wallet';

Expand All @@ -8,10 +11,12 @@ export interface CoinbaseWalletOptions {
appIcon?: string;
}

export const coinbaseWallet = ({
appName,
appIcon,
}: CoinbaseWalletOptions): Wallet => {
interface CoinbaseWallet {
(params: CoinbaseWalletOptions): Wallet;
preference?: CoinbaseWalletParameters<'4'>['preference'];
}

export const coinbaseWallet: CoinbaseWallet = ({ appName, appIcon }) => {
const getUri = (uri: string) => uri;
const ios = isIOS();

Expand Down Expand Up @@ -97,6 +102,7 @@ export const coinbaseWallet = ({
const connector: CreateConnectorFn = coinbaseConnector({
appName,
appLogoUrl: appIcon,
preference: coinbaseWallet.preference,
});

return createConnector((config) => ({
Expand Down