-
Notifications
You must be signed in to change notification settings - Fork 630
Connect Wallet v2 #584
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
Connect Wallet v2 #584
Changes from 168 commits
4d4d8cd
589c7f8
b9cf6cb
a85fa31
79d4296
919aeb2
fcae2b2
6c04ae8
2108000
33120ee
4b4ef5d
c54c6a9
84758a4
a7551c7
81e190f
42ccc92
0a8769f
dcf2bcf
d1cd067
662cff8
6790ead
b2f31bb
85691e2
3d8b2d4
9cb7f1e
9283bfe
63790cc
8c34466
ad70131
62c6751
05066ad
8f3d0f4
533df42
e663e73
384466d
82ac73a
c4470ef
86d93fa
ce64a3b
f759304
445b5fe
e0bfd36
2a147de
ea638b2
d7216d5
f5b9fb0
68175f8
411287c
7ccd9fd
6c38a17
8a47293
ee658d8
192bce9
e620908
21ed641
a796094
3ddc1c1
553ecdb
8a2a2f8
4a60fc1
69c116b
f9a0366
2641531
8b05c66
cd85af1
b430c30
4c715b6
4a25fd3
4f6fc47
ce046b0
c017ad0
117e730
ec4fd64
82ff82f
b433fab
1aacb70
9628065
6359b0b
8391904
affb5c0
9af4549
c371a2c
1f7b03b
abffb61
6b719fe
48d105c
b4ba996
dbf78f4
b7d839f
b7afc59
4a5f525
1fa9011
6a34efd
a86edae
78d9b9d
ce84144
20c266c
1851180
783a333
5d7d6c2
760abfc
d0bdc1c
9a7c8cb
f1c1568
ac2cce8
4478e93
92428c1
42bbfe3
05c72ea
e8e0233
6acaa8b
b6ef45b
3455adc
4833150
5c58481
ce0afeb
d6ebc68
5988a94
f13f2b9
9f773e6
664477c
8a429cc
36686db
b79ab34
f47d307
091df16
7249413
5052fed
27704b7
c1cc7af
f1d9c8b
cab64a6
08e2d20
044b70c
c8705e3
8f23705
6ce559b
be10b9a
c5cebd3
91688d8
805eb29
9f0e884
11b3bff
4716431
822305b
bcd28aa
21036c4
fd89b36
90f030c
dd5c27f
f71d50f
3d17099
0841a56
3729c69
9cfed81
b442267
81f7c5c
6bc9065
2a2b4ae
2073809
4755994
02d3b22
2a4209b
cf06040
a598922
3275c4d
88f2017
4aa1ab4
a8fbe72
1c24140
3bb9a6c
6ce6e19
bce6590
a226acf
e649559
48d404b
71597ea
f3f1f16
802306f
ffa1d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@thirdweb-dev/react-core": major | ||
| "@thirdweb-dev/react-native-compat": minor | ||
| "@thirdweb-dev/react-native": minor | ||
| "@thirdweb-dev/wallets": minor | ||
| "@thirdweb-dev/chains": patch | ||
| "@thirdweb-dev/sdk": patch | ||
| --- | ||
|
|
||
| Connect Wallet V2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,10 @@ | |
| "release": "node ./scripts/pre-release.mjs && changeset publish", | ||
| "version-packages:nightly": "changeset version --snapshot nightly", | ||
| "release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly", | ||
| "push": "turbo run push --filter=./packages/*" | ||
| "push": "turbo run push --filter=./packages/*", | ||
| "hotlink-init": "node ./scripts/hotlink/hotlink-init.mjs", | ||
| "hotlink-revert": "node ./scripts/hotlink/hotlink-revert.mjs", | ||
| "postinstall": "patch-package" | ||
| }, | ||
| "packageManager": "[email protected]", | ||
| "dependencies": { | ||
|
|
@@ -39,6 +42,7 @@ | |
| "@trivago/prettier-plugin-sort-imports": "^4.0.0", | ||
| "eslint": "^8.21.0", | ||
| "mocha": "^10.2.0", | ||
| "patch-package": "^6.5.1", | ||
| "postinstall-postinstall": "^2.1.0", | ||
| "prettier": "^2.7.1", | ||
| "turbo": "^1.8.3", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| export default { | ||
| "name": "Palette Chain Mainnet", | ||
| "chain": "PLT", | ||
| "rpc": [ | ||
| "https://palette-chain.rpc.thirdweb.com/${THIRDWEB_API_KEY}", | ||
| "https://palette-rpc.com:22000" | ||
| ], | ||
| "faucets": [], | ||
| "nativeCurrency": { | ||
| "name": "Palette Token", | ||
| "symbol": "PLT", | ||
| "decimals": 18 | ||
| }, | ||
| "features": [], | ||
| "infoURL": "https://hashpalette.com/", | ||
| "shortName": "PaletteChain", | ||
| "chainId": 1718, | ||
| "networkId": 1718, | ||
| "icon": { | ||
| "url": "ipfs://QmPCEGZD1p1keTT2YfPp725azx1r9Ci41hejeUuGL2whFA", | ||
| "width": 800, | ||
| "height": 800, | ||
| "format": "png" | ||
| }, | ||
| "explorers": [ | ||
| { | ||
| "name": "Palettescan", | ||
| "url": "https://palettescan.com", | ||
| "icon": "PLT", | ||
| "standard": "none" | ||
| } | ||
| ], | ||
| "testnet": false, | ||
| "slug": "palette-chain" | ||
| } as const; |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const TW_WC_PROJECT_ID = "145769e410f16970a79ff77b2d89a1e0"; | ||
| export const WC_RELAY_URL = "wss://relay.walletconnect.com"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { useThirdwebWallet } from "../providers/thirdweb-wallet-provider"; | ||
| import invariant from "tiny-invariant"; | ||
|
|
||
| /** | ||
| * @returns the current active wallet instance | ||
| */ | ||
| export function useWallet() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useWallet() hook must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.activeWallet; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns `supportedWallets` configured in the `<ThirdwebProvider/>` | ||
| */ | ||
| export function useWallets() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useWallets() hook must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.wallets; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns a method to connect to a wallet class | ||
| */ | ||
| export function useConnect() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useConnect() hook must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.connect; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns a method to disconnect from the current active wallet | ||
| */ | ||
| export function useDisconnect() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useDisconnect() hook must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.disconnect; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns the connection status of the wallet | ||
| * | ||
| * It can be one of the following: | ||
| * 1. `unknown` - when wallet connection status is not yet known | ||
| * 2. `connecting` - when wallet is connecting | ||
| * 3. `connected` - when wallet is connected | ||
| * 4. `disconnected` - when wallet is disconnected | ||
| * | ||
| */ | ||
| export function useConnectionStatus() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useConnectionStatus() must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.connectionStatus; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns a method to create an instance of given wallet class | ||
| */ | ||
| export function useCreateWalletInstance() { | ||
|
Member
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. is this a public API? what is it used for?
Member
Author
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. It can be a public API, user can use it to create a wallet instance. This abstracts away the complexity of creating a wallet instance ( Wallet constructor takes a bunch of things as argument ) const createInstance = useCreateWalletInstance();
// when we need to create an instance, we do:
const metamask = createInstance(MetamaskWallet)
// MetamaskWallet is a class
// metamask is wallet instance |
||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useCreateWalletInstance() must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.createWalletInstance; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns a method to connect the wallet to network/chain with given chainId | ||
| */ | ||
| export function useSwitchChain() { | ||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useSwitchChain() must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.switchChain; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns a method to get the chainId of currently connected network/chain | ||
| */ | ||
| export function useActiveChainId() { | ||
|
||
| const context = useThirdwebWallet(); | ||
| invariant( | ||
| context, | ||
| "useActiveChainId() must be used within a <ThirdwebProvider/>", | ||
| ); | ||
| return context.activeChainId; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { createContext } from "react"; | ||
|
|
||
| export const ThirdwebThemeContext = createContext<"light" | "dark" | undefined>( | ||
| undefined, | ||
| ); |
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.
what causes
unknown? just a loading state? can we make itloadingin that case?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.
status starts out with
unknown- because when the app is loading, we just don't know statusHere are two possible scenarios when app is loading:
unknown=>connecting=>connectedunknown=>disconnectedWe can make it
loadinginstead ofunknownbut it sounds a bit similar toconnecting- it feels like we are trying to "connect" but we are not. Let me know what you think, I'm fine with either