-
Notifications
You must be signed in to change notification settings - Fork 587
[SDK] Add apechain to supported chains and Add Glyph Wallet Connector #8034
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
Closed
shubham-yuga
wants to merge
6
commits into
thirdweb-dev:main
from
shubham-yuga:use-glyph/handle-glyph-connector
+245
−31
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6af732e
[SDK] Feature: added chain definitions for apechain and curtis
shubham-yuga f647a2f
[Playground-Web] Feature: Added Glyph Wallet
shubham-yuga 7a057b5
[SDK] Feature: Handle Glyph Wallet in the CreateWallet function such …
shubham-yuga a77a74f
generate changeset
shubham-yuga a809e59
[SDK] Feature: Export Glyph Wallet Connectors. Some Refactoring and A…
shubham-yuga 78066d1
Merge branch 'main' into use-glyph/handle-glyph-connector
shubham-yuga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"thirdweb": minor | ||
--- | ||
|
||
Add Glyph wallet connector to `createWallet`, export the connector and also export new chains: | ||
|
||
- `apechain` (mainnet) | ||
- `curtis` (testnet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/thirdweb/src/chains/chain-definitions/apechain.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineChain } from "../utils.js"; | ||
|
||
/** | ||
* @chain | ||
*/ | ||
export const apechain = /* @__PURE__ */ defineChain({ | ||
blockExplorers: [ | ||
{ | ||
name: "Apescan", | ||
url: "https://apescan.io", | ||
}, | ||
], | ||
id: 33139, | ||
name: "Ape Chain", | ||
nativeCurrency: { | ||
name: "ApeCoin", | ||
symbol: "APE", | ||
decimals: 18, | ||
}, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { defineChain } from "../utils.js"; | ||
|
||
/** | ||
* @chain | ||
* Curtis test network (Ape Chain testnet variant). | ||
*/ | ||
export const curtis = /* @__PURE__ */ defineChain({ | ||
blockExplorers: [ | ||
{ | ||
name: "Curtis Explorer", | ||
url: "https://explorer.curtis.apechain.com", | ||
}, | ||
], | ||
id: 33_111, | ||
name: "Curtis", | ||
nativeCurrency: { name: "ApeCoin", symbol: "APE", decimals: 18 }, | ||
testnet: true, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
glyphWalletTW, | ||
glyphWalletWagmiConnector, | ||
} from "../../wallets/glyph/glyph-wallet.js"; | ||
shubham-yuga marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm these should be in their own package, not directly baked into the thirdweb package. Same thing we do with abstract global wallet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** Staging tenant id for Glyph Cross-App Connect. @internal */ | ||
export const STAGING_GLYPH_APP_ID = "clxt9p8e601al6tgmsyhu7j3t"; | ||
/** Production tenant id for Glyph Cross-App Connect. @internal */ | ||
export const GLYPH_APP_ID = "cly38x0w10ac945q9yg9sm71i"; | ||
/** Icon used in connectors & UIs. @internal */ | ||
export const GLYPH_ICON_URL = "https://i.ibb.co/TxcwPQyr/Group-12489-1.png"; | ||
|
||
export const glyphConnectorDetails = { | ||
id: "io.useglyph.privy", | ||
name: "Glyph", | ||
iconUrl: GLYPH_ICON_URL, | ||
iconBackground: "#ffffff", | ||
shortName: "Glyph", | ||
type: "injected", | ||
} as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { toPrivyWalletConnector } from "@privy-io/cross-app-connect/rainbow-kit"; | ||
import type { CreateConnectorFn } from "@wagmi/core"; | ||
import { createEmitter } from "@wagmi/core/internal"; | ||
import type { Chain, EIP1193Provider } from "viem"; | ||
import { | ||
abstract, | ||
apeChain, | ||
arbitrum, | ||
arbitrumSepolia, | ||
base, | ||
baseSepolia, | ||
curtis, | ||
mainnet, | ||
optimism, | ||
optimismSepolia, | ||
polygon, | ||
sepolia, | ||
} from "viem/chains"; | ||
import { fromProvider } from "../../adapters/eip1193/from-eip1193.js"; | ||
import { | ||
GLYPH_APP_ID, | ||
glyphConnectorDetails, | ||
STAGING_GLYPH_APP_ID, | ||
} from "../../wallets/glyph/constants.js"; | ||
import type { Wallet } from "../../wallets/interfaces/wallet.js"; | ||
|
||
/** | ||
* Create a wagmi connector for the Glyph Global Wallet. | ||
* | ||
* Adapted from wagmi injected connector as a reference implementation: | ||
* https://github.com/wevm/wagmi/blob/main/packages/core/src/connectors/injected.ts#L94 | ||
* | ||
* @example | ||
* import { createConfig, http } from "wagmi"; | ||
* import { apeChain } from "wagmi/chains"; | ||
* import { glyphWalletWagmiConnector } from "thirdweb/wallets/glyph" | ||
* | ||
* export const wagmiConfig = createConfig({ | ||
* chains: [apeChain], | ||
* transports: { | ||
* [apeChain.id]: http(), | ||
* }, | ||
* connectors: [glyphWalletWagmiConnector()], | ||
* ssr: true, | ||
* }); | ||
*/ | ||
function glyphWalletWagmiConnector(options?: { | ||
useStagingTenant?: boolean; | ||
}): CreateConnectorFn { | ||
const { useStagingTenant } = options ?? {}; | ||
|
||
return (params) => { | ||
const connector = toPrivyWalletConnector({ | ||
iconUrl: glyphConnectorDetails.iconUrl, | ||
id: useStagingTenant ? STAGING_GLYPH_APP_ID : GLYPH_APP_ID, | ||
name: glyphConnectorDetails.name, | ||
})(params); | ||
|
||
const getGlyphProvider = async ( | ||
parameters?: { chainId?: number | undefined } | undefined, | ||
) => { | ||
const chainId = | ||
parameters?.chainId ?? params.chains?.[0]?.id ?? apeChain.id; | ||
|
||
shubham-yuga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const provider = await connector.getProvider({ | ||
chainId, | ||
}); | ||
|
||
return provider; | ||
}; | ||
|
||
const glyphConnector = { | ||
...connector, | ||
getProvider: getGlyphProvider, | ||
type: glyphConnectorDetails.type, | ||
id: glyphConnectorDetails.id, | ||
}; | ||
return glyphConnector; | ||
}; | ||
} | ||
|
||
/** | ||
* Create a thirdweb wallet for Glyph Global Wallet | ||
* | ||
* @returns A wallet instance wrapping Glyph Global Wallet to be used with the thirdweb Connect SDK | ||
* | ||
* @example | ||
* ```tsx | ||
* import { createThirdwebClient } from "thirdweb"; | ||
* import { glyphWalletTW } from "thirdweb/wallets/glyph" | ||
* | ||
* const client = createThirdwebClient({ clientId }); | ||
* | ||
* <ConnectButton client={client} wallets=[glyphWalletTW()]> | ||
* ``` | ||
*/ | ||
function glyphWalletTW(chains?: [Chain, ...Chain[]]): Wallet { | ||
const connector = glyphWalletWagmiConnector()({ | ||
chains: chains ?? [ | ||
apeChain, | ||
curtis, | ||
mainnet, | ||
base, | ||
arbitrum, | ||
polygon, | ||
optimism, | ||
abstract, | ||
sepolia, | ||
baseSepolia, | ||
optimismSepolia, | ||
arbitrumSepolia, | ||
], | ||
emitter: createEmitter("io.useglyph"), | ||
}); | ||
return fromProvider({ | ||
provider: connector.getProvider as ( | ||
parameters?: { chainId?: number | undefined } | undefined, | ||
) => Promise<EIP1193Provider>, | ||
walletId: "io.useglyph", | ||
}); | ||
} | ||
|
||
export { glyphWalletTW, glyphWalletWagmiConnector }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah these dependencies cannot be here. Needs to be its own package and users will install both your package and thirdweb together. Check how we do it for abstract