Skip to content

Commit 7a057b5

Browse files
committed
[SDK] Feature: Handle Glyph Wallet in the CreateWallet function such that it works at all places
1 parent f647a2f commit 7a057b5

File tree

8 files changed

+141
-417
lines changed

8 files changed

+141
-417
lines changed

apps/playground-web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"dependencies": {
33
"@abstract-foundation/agw-react": "^1.6.4",
4-
"@use-glyph/sdk-react": "1.2.2",
54
"@ai-sdk/react": "^2.0.25",
65
"@hookform/resolvers": "^3.9.1",
76
"@radix-ui/react-avatar": "^1.1.10",

apps/playground-web/src/app/wallets/sign-in/button/RightSection.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb";
2-
import { glyphWalletTW } from "@use-glyph/sdk-react";
32
import { XIcon } from "lucide-react";
43
import { usePathname } from "next/navigation";
54
import { useEffect, useState } from "react";
@@ -241,8 +240,6 @@ function getWallets(connectOptions: ConnectPlaygroundOptions) {
241240
...connectOptions.walletIds.map((id) => {
242241
if (id === "xyz.abs") {
243242
return abstractWallet();
244-
} if( id === "io.useglyph") {
245-
return glyphWalletTW();
246243
}
247244
return createWallet(id);
248245
}),

packages/thirdweb/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@noble/curves": "1.8.2",
1818
"@noble/hashes": "1.7.2",
1919
"@passwordless-id/webauthn": "^2.1.2",
20+
"@privy-io/cross-app-connect": ">=0.2.3",
2021
"@radix-ui/react-dialog": "1.1.14",
2122
"@radix-ui/react-focus-scope": "1.1.7",
2223
"@radix-ui/react-icons": "1.3.2",
@@ -25,6 +26,7 @@
2526
"@tanstack/react-query": "5.81.5",
2627
"@thirdweb-dev/engine": "workspace:*",
2728
"@thirdweb-dev/insight": "workspace:*",
29+
"@wagmi/core": ">=2.17.2",
2830
"@walletconnect/sign-client": "2.20.1",
2931
"@walletconnect/universal-provider": "2.21.4",
3032
"abitype": "1.0.8",

packages/thirdweb/src/wallets/create-wallet.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { coinbaseWalletSDK } from "./coinbase/coinbase-wallet.js";
1414
import { getCoinbaseWebProvider } from "./coinbase/coinbase-web.js";
1515
import { COINBASE } from "./constants.js";
1616
import { isEcosystemWallet } from "./ecosystem/is-ecosystem-wallet.js";
17+
import { glyphWalletTW } from "./glyph/glyph-wallet.js";
1718
import { ecosystemWallet } from "./in-app/web/ecosystem.js";
1819
import { inAppWallet } from "./in-app/web/in-app.js";
1920
import { getInjectedProvider } from "./injected/index.js";
@@ -185,6 +186,14 @@ export function createWallet<const ID extends WalletId>(
185186
providerFactory: () => getCoinbaseWebProvider(options),
186187
}) as Wallet<ID>;
187188
}
189+
190+
/**
191+
* GLYPH WALLET
192+
*/
193+
case id === "io.useglyph": {
194+
return glyphWalletTW() as Wallet<ID>;
195+
}
196+
188197
/**
189198
* WALLET CONNECT AND INJECTED WALLETS + walletConnect standalone
190199
*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const STAGING_GLYPH_APP_ID = 'clxt9p8e601al6tgmsyhu7j3t';
2+
export const GLYPH_APP_ID = 'cly38x0w10ac945q9yg9sm71i';
3+
export const GLYPH_ICON_URL = 'https://i.ibb.co/TxcwPQyr/Group-12489-1.png';
4+
5+
export const glyphConnectorDetails = {
6+
id: 'io.useglyph.privy',
7+
name: 'Glyph',
8+
iconUrl: GLYPH_ICON_URL,
9+
iconBackground: '#ffffff',
10+
shortName: 'Glyph',
11+
type: 'injected',
12+
} as const;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { toPrivyWalletConnector } from "@privy-io/cross-app-connect/rainbow-kit";
2+
import type { CreateConnectorFn } from "@wagmi/core";
3+
import { createEmitter } from "@wagmi/core/internal";
4+
import { fromProvider } from "../../adapters/eip1193/from-eip1193.js";
5+
import { apechain } from "../../chains/chain-definitions/apechain.js";
6+
import { GLYPH_APP_ID, glyphConnectorDetails, STAGING_GLYPH_APP_ID } from "../../wallets/glyph/constants.js";
7+
import type { Wallet } from "../../wallets/interfaces/wallet.js";
8+
import type { Chain, EIP1193Provider } from "viem";
9+
import { abstract, apeChain, arbitrum, arbitrumSepolia, base, baseSepolia, curtis, mainnet, optimism, optimismSepolia, polygon, sepolia } from "viem/chains";
10+
11+
/**
12+
* Create a wagmi connector for the Glyph Global Wallet.
13+
*
14+
* Adapted from wagmi injected connector as a reference implementation:
15+
* https://github.com/wevm/wagmi/blob/main/packages/core/src/connectors/injected.ts#L94
16+
*
17+
* @example
18+
* import { createConfig, http } from "wagmi";
19+
* import { apeChain } from "wagmi/chains";
20+
* import { glyphWalletConnector } from "@use-glyph/sdk-react"
21+
*
22+
* export const wagmiConfig = createConfig({
23+
* chains: [apeChain],
24+
* transports: {
25+
* [apeChain.id]: http(),
26+
* },
27+
* connectors: [glyphWalletConnector()],
28+
* ssr: true,
29+
* });
30+
*/
31+
function glyphWalletConnector(options?: {
32+
useStagingTenant?: boolean
33+
}): CreateConnectorFn {
34+
const { useStagingTenant } = options ?? {};
35+
36+
return (params) => {
37+
const connector = toPrivyWalletConnector({
38+
iconUrl: glyphConnectorDetails.iconUrl,
39+
id: useStagingTenant ? STAGING_GLYPH_APP_ID : GLYPH_APP_ID,
40+
name: glyphConnectorDetails.name
41+
})(params);
42+
43+
const getGlyphProvider = async (parameters?: { chainId?: number | undefined } | undefined) => {
44+
const chainId = parameters?.chainId ?? params.chains?.[0]?.id ?? apechain.id;
45+
46+
const provider = await connector.getProvider({
47+
chainId
48+
});
49+
50+
return provider;
51+
};
52+
53+
const glyphConnector = {
54+
...connector,
55+
getProvider: getGlyphProvider,
56+
type: glyphConnectorDetails.type,
57+
id: glyphConnectorDetails.id
58+
};
59+
return glyphConnector;
60+
};
61+
}
62+
63+
/**
64+
* Create a thirdweb wallet for Glyph Global Wallet
65+
*
66+
* @returns A wallet instance wrapping Glyph Global Wallet to be used with the thirdweb Connect SDK
67+
*
68+
* @example
69+
* ```tsx
70+
* import { createThirdwebClient } from "thirdweb";
71+
* import { glyphWalletTW } from "@use-glyph/sdk-react"
72+
*
73+
* const client = createThirdwebClient({ clientId });
74+
*
75+
* <ConnectButton client={client} wallets=[glyphWalletTW()]>
76+
* ```
77+
*/
78+
const glyphWalletTW = (chains?: [Chain, ...Chain[]]): Wallet => {
79+
const connector = glyphWalletConnector()({
80+
chains: chains ?? [apeChain, curtis, mainnet, base, arbitrum, polygon, optimism, abstract, sepolia, baseSepolia, optimismSepolia, arbitrumSepolia],
81+
emitter: createEmitter("io.useglyph")
82+
});
83+
return fromProvider({
84+
provider: connector.getProvider as (
85+
parameters?: { chainId?: number | undefined } | undefined
86+
) => Promise<EIP1193Provider>,
87+
walletId: "io.useglyph"
88+
});
89+
};
90+
91+
export { glyphWalletTW };

packages/thirdweb/src/wallets/native/create-wallet.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getCoinbaseMobileProvider } from "../coinbase/coinbase-mobile.js";
1010
import { coinbaseWalletSDK } from "../coinbase/coinbase-wallet.js";
1111
import { COINBASE } from "../constants.js";
1212
import { isEcosystemWallet } from "../ecosystem/is-ecosystem-wallet.js";
13+
import { glyphWalletTW } from "../glyph/glyph-wallet.js";
1314
import { ecosystemWallet } from "../in-app/native/ecosystem.js";
1415
import { inAppWallet } from "../in-app/native/in-app.js";
1516
import type { Account, Wallet } from "../interfaces/wallet.js";
@@ -23,6 +24,7 @@ import type {
2324
WalletId,
2425
} from "../wallet-types.js";
2526

27+
2628
/**
2729
* Creates a wallet based on the provided ID and arguments.
2830
* @param args - The arguments for creating the wallet.
@@ -85,6 +87,13 @@ export function createWallet<const ID extends WalletId>(
8587
}) as Wallet<ID>;
8688
}
8789

90+
/**
91+
* GLYPH WALLET
92+
*/
93+
case id === "io.useglyph": {
94+
return glyphWalletTW() as Wallet<ID>;
95+
}
96+
8897
/**
8998
* WALLET CONNECT only in react native for everything else
9099
*/

0 commit comments

Comments
 (0)