Skip to content

Commit

Permalink
add thirdweb connector
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Nov 13, 2024
1 parent e3e2ad8 commit 68fa560
Show file tree
Hide file tree
Showing 5 changed files with 1,490 additions and 30 deletions.
10 changes: 10 additions & 0 deletions packages/agw-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"import": "./dist/esm/exports/privy.js",
"require": "./dist/cjs/exports/privy.js"
},
"./thirdweb": {
"types": "./dist/types/exports/thirdweb.d.ts",
"import": "./dist/esm/exports/thirdweb.js",
"require": "./dist/cjs/exports/thirdweb.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
Expand All @@ -61,6 +66,7 @@
"@tanstack/react-query": "^5",
"react": ">=18",
"typescript": ">=5.0.4",
"thirdweb": "^5.68.0",
"viem": "^2.21.26",
"wagmi": "^2"
},
Expand All @@ -75,11 +81,15 @@
"@wagmi/core": "^2",
"react": ">=18.3.1",
"react-dom": ">=18.3.1",
"thirdweb": "^5.68.0",
"viem": "^2.21.26"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
},
"thirdweb": {
"optional": true
}
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/agw-react/src/abstractWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { abstractTestnet } from 'viem/chains';
import { AGW_APP_ID, ICON_URL } from './constants.js';

// TODO: support Abstract mainnet
const VALID_CHAINS: Record<number, Chain> = {
export const VALID_CHAINS: Record<number, Chain> = {
[abstractTestnet.id]: abstractTestnet,
};

Expand Down
36 changes: 36 additions & 0 deletions packages/agw-react/src/abstractWalletThirdweb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createEmitter } from '@wagmi/core/internal';
import { EIP1193, type Wallet } from 'thirdweb/wallets';
import type { Chain } from 'viem/chains';

import {
abstractWalletConnector,
VALID_CHAINS,
} from './abstractWalletConnector.js';

/**
* Create a thirdweb wallet for Abstract Global Wallet
*
* @returns A wallet instance wrapping Abstract Global Wallet to be used with the thirdweb Connect SDK
*
* @example
* ```tsx
* import { createThirdwebClient } from "thirdweb";
* import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb"
*
* const client = createThirdwebClient({ clientId });
*
* <ConnectButton client={client} wallets=[abstractWallet()]>
* ```
*/
const abstractWallet = (): Wallet => {
const connector = abstractWalletConnector()({
chains: Object.values(VALID_CHAINS) as [Chain, ...Chain[]],
emitter: createEmitter('xyz.abs'),
});
return EIP1193.fromProvider({
provider: connector.getProvider,
walletId: 'xyz.abs',
});
};

export { abstractWallet };
1 change: 1 addition & 0 deletions packages/agw-react/src/exports/thirdweb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { abstractWallet } from '../abstractWalletThirdweb.js';
Loading

0 comments on commit 68fa560

Please sign in to comment.