@dogeos/dogeos-sdk 4.0.6-beta.2 → 4.0.7-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,6 +112,38 @@ Use the state that matches what your app needs.
112
112
 
113
113
  Inside MyDoge, the SDK selects the native wallet automatically. Keep your normal provider configuration and connection button. A native or external wallet can be connected while the embedded wallet is disabled, so do not require `isWalletReady` for all wallet actions. See [native wallet connections](https://docs.dogeos.com/en/sdk/embedded-wallets#native-first-connection-in-mydoge).
114
114
 
115
+ ## Inside the MyDoge app
116
+
117
+ In MyDoge's dApp browser the native app answers every wallet request, and the SDK shows none of its own wallet UI and opens no popups. The same code works in a browser and in MyDoge:
118
+
119
+ - `openModal()` asks MyDoge to connect, or opens MyDoge's account sheet when a wallet is already connected.
120
+ - `WalletConnectEmbed` shows a small MyDoge card with Connect, Account and Disconnect buttons instead of the wallet list.
121
+ - A first visit does not prompt on page load. MyDoge reconnects a dApp the user already approved; otherwise the SDK waits for the user to tap connect.
122
+ - `disconnect()` also revokes the dApp's approval in MyDoge.
123
+ - DogeOS email and social sign-in (`useDogeOSAuth().login()`) reject with `DogeOSHostError`. Use `signInWithWallet()` and verify the signature on your server.
124
+
125
+ `useWalletHost()` tells you where the dApp is running and gives you a connect call that returns the account in both places:
126
+
127
+ ```tsx
128
+ import { isWalletError, useWalletHost, WalletErrorCode } from "@dogeos/dogeos-sdk";
129
+
130
+ function ConnectButton() {
131
+ const { isNativeHost, connect } = useWalletHost();
132
+
133
+ const onClick = async () => {
134
+ try {
135
+ const { address } = await connect();
136
+ console.log("Connected", address);
137
+ } catch (error) {
138
+ if (isWalletError(error, WalletErrorCode.UserRejected)) return;
139
+ throw error;
140
+ }
141
+ };
142
+
143
+ return <button type="button" onClick={onClick}>{isNativeHost ? "Connect MyDoge" : "Connect wallet"}</button>;
144
+ }
145
+ ```
146
+
115
147
  ## Configure your app
116
148
 
117
149
  Pass optional settings alongside `clientId` in `WalletConnectKitConfig`.
@@ -163,6 +195,45 @@ export function WalletPanel() {
163
195
  }
164
196
  ```
165
197
 
198
+ ## Link to another dApp from inside MyDoge
199
+
200
+ In MyDoge's in-app browser, a plain `https` link to another dApp loads in your dApp's browser session. The wallet stays bound to your dApp's origin, so the other dApp can't connect. Link to it with a `mydoge://dapp` URL instead: MyDoge then opens the target as its own dApp with its own wallet session. The user sees the target's details screen and taps **Open**; your dApp closes only then.
201
+
202
+ `isInMyDogeBrowser()` detects MyDoge's in-app browser through its EIP-6963 announcement (rdns `com.mydoge.wallet`). It resolves `false` after a timeout (500 ms by default) and during server rendering. `getDappHref()` returns the `mydoge://dapp` link inside MyDoge and the plain URL everywhere else.
203
+
204
+ ```tsx
205
+ "use client";
206
+
207
+ import { useEffect, useState } from "react";
208
+ import { getDappHref, isInMyDogeBrowser } from "@dogeos/dogeos-sdk";
209
+
210
+ const BUY_MOON_URL = "https://muchfi.example/buy?token=MOON";
211
+
212
+ export function BuyMoonLink() {
213
+ // null until detection finishes, so no plain link can be tapped inside MyDoge first.
214
+ const [inMyDoge, setInMyDoge] = useState<boolean | null>(null);
215
+
216
+ useEffect(() => {
217
+ void isInMyDogeBrowser().then(setInMyDoge);
218
+ }, []);
219
+
220
+ const href = inMyDoge === null ? undefined : getDappHref(BUY_MOON_URL, { inMyDoge });
221
+ return <a href={href}>Buy MOON</a>;
222
+ }
223
+ ```
224
+
225
+ Leave the link without an `href` until detection finishes. A server-rendered plain link can be tapped inside MyDoge before your page hydrates, which loads the target in your dApp's session. Outside MyDoge, detection takes up to 500 ms after hydration.
226
+
227
+ `getMyDogeDappLink(targetUrl)` builds the link directly: `mydoge://dapp?url=` followed by the complete target URL, encoded once with `encodeURIComponent`. Pass the raw `https` URL, not an already encoded one. It normalizes the URL first, as a browser would (for example, a space becomes `%20`), because MyDoge rejects raw spaces and similar characters. It throws a `TypeError` for anything other than an absolute `https` URL, for a URL with a username or password, and for a URL over MyDoge's 8 KiB limit. `getDappHref()` applies the same checks in every browser, so a bad URL shows up in ordinary testing.
228
+
229
+ These rules come from MyDoge's dApp deep-link partner guide:
230
+
231
+ - **Set the href before the tap.** Detect MyDoge first, then put the link in the element the user taps. A plain link, a `target="_blank"` link, or `window.open` called synchronously in the tap handler all work. Setting `location.href` doesn't work on iOS, and navigation after an `await` or a timer may be blocked.
232
+ - **Only top-level pages work.** Links inside an iframe are ignored on iOS and may be ignored on Android.
233
+ - **The target must be listed in MyDoge.** Its origin must exactly match the destination dApp's published CMS `projectLink` origin. Subdomains such as `www` and non-default ports count as different origins. Path, query and fragment are passed through unchanged.
234
+ - **MyDoge 3.1.1 (build 652) or later is required.** Earlier builds ignore a tapped `mydoge://` link, so nothing happens. They announce the same `com.mydoge.wallet` provider, so a page can't tell them apart from 652.
235
+ - MyDoge ignores a second link within two seconds.
236
+
166
237
  ## Documentation
167
238
 
168
239
  - [Quickstart](https://docs.dogeos.com/en/sdk) for installation and provider setup.