-
Notifications
You must be signed in to change notification settings - Fork 97
docs: fix wallet discovery using fixed window.midnight.mnLace key #1080
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -149,9 +149,15 @@ const App: React.FC = () => { | |
| let address = null; | ||
|
|
||
| try { | ||
| // Access the Midnight Lace wallet through the window object | ||
| const wallet: InitialAPI = window.midnight!.mnLace; | ||
|
|
||
| // Wallets inject their Initial API into `window.midnight` under a | ||
| // wallet-specific key (not a fixed key like `mnLace`), so look it up | ||
| // by the `name` property instead of assuming the key. | ||
| const wallets = Object.values(window.midnight ?? {}); | ||
| const wallet: InitialAPI | undefined = wallets.find((w) => w.name === 'Lace'); | ||
| if (!wallet) { | ||
| throw new Error('Lace wallet not found. Please install the Lace wallet extension.'); | ||
| } | ||
|
Comment on lines
+152
to
+159
Contributor
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. This entire block targets code that no longer exists on Please rebase onto |
||
|
|
||
| // Connect to the specified network (use 'undeployed' for local development) | ||
| const connectedApi = await wallet.connect('preprod'); | ||
|
|
||
|
|
@@ -204,8 +210,8 @@ export default App; | |
|
|
||
| Let's break down the wallet connection process: | ||
|
|
||
| 1. **Access the wallet**: The DApp Connector API exposes the wallet through `window.midnight.{walletProvider}`. | ||
| In our example, we used `window.midnight.mnLace` to access the Midnight Lace wallet. | ||
| 1. **Access the wallet**: The DApp Connector API exposes each wallet through `window.midnight.{walletId}`, where `{walletId}` is a wallet-specific key chosen by the wallet (not a fixed value). | ||
| In our example, we find the Lace wallet by looking up `window.midnight` values whose `name` property is `'Lace'`. | ||
| 2. **Connect to network**: Call the `connect()` method and pass the network ID as an argument. | ||
| In our example, we used `'undeployed'` for local development. You can use `'preview'` for the Preview testnet or `'preprod'` for the PreProd network. | ||
| 3. **Retrieve addresses**: After connecting to the network, call the `getShieldedAddresses()` method to get the wallet's shielded address. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -793,8 +793,10 @@ The example below shows how a DApp connects to and interacts with a Lace Midnigh | |||||||||
| ```typescript | ||||||||||
| import { nativeToken } from '@midnight-ntwrk/ledger-v8'; | ||||||||||
|
|
||||||||||
| // Check if wallet is available | ||||||||||
| const wallet = window.midnight?.mnLace; | ||||||||||
| // Wallets inject their Initial API into `window.midnight` under a | ||||||||||
| // wallet-specific key (not a fixed key like `mnLace`), so look it up | ||||||||||
| // by the `name` property instead of assuming the key. | ||||||||||
|
Comment on lines
+796
to
+798
Contributor
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. Same note: drop the
Suggested change
|
||||||||||
| const wallet = Object.values(window.midnight ?? {}).find((w) => w.name === 'Lace'); | ||||||||||
|
|
||||||||||
| if (!wallet) { | ||||||||||
| console.error('Please install Lace Midnight wallet'); | ||||||||||
|
|
||||||||||
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.
Tutorial readers have not seen the old
mnLacekey, so the counter-example adds confusion. A concise comment about what the code does is clearer.