Skip to content

Commit

Permalink
Add coinbase injected wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
MananTank committed Feb 5, 2024
1 parent 324f4b7 commit 17aebb6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
44 changes: 44 additions & 0 deletions packages/thirdweb/src/react/wallets/coinbase/coinbaseConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
injectedCoinbaseProvider,
coinbaseMetadata,
coinbaseWallet,
} from "../../../wallets/index.js";
import type { WalletConfig } from "../../types/wallets.js";
import { InjectedConnectUI } from "../shared/InjectedConnectUI.js";

/**
* Integrate Coinbase wallet connection into your app.
* @example
* ```tsx
* <ThirdwebProvider
* client={client}>
* wallets={[ coinbaseConfig() ]}
* <App />
* </ThirdwebProvider>
* ```
* @returns WalletConfig object to be passed into `ThirdwebProvider`
*/
export const coinbaseConfig = (): WalletConfig => {
return {
metadata: coinbaseMetadata,
create() {
return coinbaseWallet();
},
connectUI(props) {
return (
<InjectedConnectUI
{...props}
links={{
extension:
"https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad",
android: "https://play.google.com/store/apps/details?id=org.toshi",
ios: "https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455",
}}
/>
);
},
isInstalled() {
return !!injectedCoinbaseProvider();
},
};
};
4 changes: 3 additions & 1 deletion packages/thirdweb/src/react/wallets/defaultWallets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { WalletConfig } from "../types/wallets.js";
import { coinbaseConfig } from "./coinbase/coinbaseConfig.js";
import { metamaskConfig } from "./metamask/metamaskConfig.js";
import { rainbowConfig } from "./rainbow/rainbowConfig.js";
import { zerionConfig } from "./zerion/zerionConfig.js";

export const defaultWallets: WalletConfig[] = [
/* @__PURE__ */ metamaskConfig(),
/* @__PURE__ */ zerionConfig(),
/* @__PURE__ */ coinbaseConfig(),
/* @__PURE__ */ rainbowConfig(),
/* @__PURE__ */ zerionConfig(),
];
8 changes: 8 additions & 0 deletions packages/thirdweb/src/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export {

// injected
export { injectedWallet } from "./injected/index.js";
export { getMIPDStore } from "./injected/mipdStore.js";

export type {
WalletRDNS,
InjectedWalletOptions,
Expand All @@ -27,6 +29,12 @@ export {
metamaskMetadata,
} from "./injected/wallets/metamask.js";

export {
injectedCoinbaseProvider,
coinbaseMetadata,
coinbaseWallet,
} from "./injected/wallets/coinbase.js";

export {
rainbowWallet,
rainbowWalletMetadata,
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/wallets/injected/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { WalletMetadata } from "../types.js";

export type WalletRDNS =
| "io.metamask"
| "com.coinbase"
| "com.coinbase.wallet"
| "io.zerion.wallet"
| "me.rainbow"
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down
40 changes: 40 additions & 0 deletions packages/thirdweb/src/wallets/injected/wallets/coinbase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { WalletMetadata } from "../../types.js";
import { InjectedWallet } from "../index.js";
import { injectedProvider } from "../mipdStore.js";
import type { SpecificInjectedWalletOptions } from "../types.js";

export const coinbaseMetadata: WalletMetadata = {
id: "com.coinbase.wallet",
name: "Coinbase Wallet",
iconUrl:
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDgiIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgMCA0OCA0OCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjQ4IiBoZWlnaHQ9IjQ4IiByeD0iOCIgZmlsbD0iIzA1NTVGRiIvPgo8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfMzMwM184NjM0KSI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xp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GVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8zMzAzXzg2MzQiPgo8cmVjdCB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIGZpbGw9IndoaXRlIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg0IDQpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==",
};

/**
* Connect to Injected Coinbase Wallet Provider
* @param options - The options for connecting to the Injected Coinbase Wallet Provider.
* @example
* ```ts
* const wallet = await coinbaseWallet();
* ```
* @returns A Promise that resolves to a Wallet instance.
*/
export function coinbaseWallet(options?: SpecificInjectedWalletOptions) {
return new InjectedWallet({
...options,
walletId: coinbaseMetadata.id,
metadata: coinbaseMetadata,
});
}

/**
* Get the injected Coinbase wallet provider
* @example
* ```ts
* const provider = injectedCoinbaseProvider();
* ```
* @returns The injected coinbase wallet provider
*/
export function injectedCoinbaseProvider() {
return injectedProvider(coinbaseMetadata.id);
}

0 comments on commit 17aebb6

Please sign in to comment.