@dubsdotapp/expo 0.2.19 → 0.2.20
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/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +31 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useClaim.ts +2 -1
- package/src/hooks/useCreateCustomGame.ts +2 -1
- package/src/hooks/useCreateGame.ts +2 -1
- package/src/hooks/useJoinGame.ts +2 -1
- package/src/managed-wallet.tsx +14 -7
- package/src/utils/transaction.ts +9 -2
- package/src/wallet/phantom-deeplink/phantom-deeplink-adapter.ts +0 -40
package/package.json
CHANGED
package/src/hooks/useClaim.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ClaimMutationResult {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function useClaim() {
|
|
13
|
-
const { client, wallet } = useDubs();
|
|
13
|
+
const { client, wallet, connection } = useDubs();
|
|
14
14
|
const [status, setStatus] = useState<MutationStatus>('idle');
|
|
15
15
|
const [error, setError] = useState<Error | null>(null);
|
|
16
16
|
const [data, setData] = useState<ClaimMutationResult | null>(null);
|
|
@@ -38,6 +38,7 @@ export function useClaim() {
|
|
|
38
38
|
const signature = await signAndSendBase64Transaction(
|
|
39
39
|
claimResult.transaction,
|
|
40
40
|
wallet,
|
|
41
|
+
connection,
|
|
41
42
|
);
|
|
42
43
|
console.log('[useClaim] Step 2 done. Signature:', signature);
|
|
43
44
|
|
|
@@ -12,7 +12,7 @@ export interface CreateCustomGameMutationResult {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function useCreateCustomGame() {
|
|
15
|
-
const { client, wallet } = useDubs();
|
|
15
|
+
const { client, wallet, connection } = useDubs();
|
|
16
16
|
const [status, setStatus] = useState<MutationStatus>('idle');
|
|
17
17
|
const [error, setError] = useState<Error | null>(null);
|
|
18
18
|
const [data, setData] = useState<CreateCustomGameMutationResult | null>(null);
|
|
@@ -40,6 +40,7 @@ export function useCreateCustomGame() {
|
|
|
40
40
|
const signature = await signAndSendBase64Transaction(
|
|
41
41
|
createResult.transaction,
|
|
42
42
|
wallet,
|
|
43
|
+
connection,
|
|
43
44
|
);
|
|
44
45
|
console.log('[useCreateCustomGame] Step 2 done. Signature:', signature);
|
|
45
46
|
|
|
@@ -11,7 +11,7 @@ export interface CreateGameMutationResult {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function useCreateGame() {
|
|
14
|
-
const { client, wallet } = useDubs();
|
|
14
|
+
const { client, wallet, connection } = useDubs();
|
|
15
15
|
const [status, setStatus] = useState<MutationStatus>('idle');
|
|
16
16
|
const [error, setError] = useState<Error | null>(null);
|
|
17
17
|
const [data, setData] = useState<CreateGameMutationResult | null>(null);
|
|
@@ -39,6 +39,7 @@ export function useCreateGame() {
|
|
|
39
39
|
const signature = await signAndSendBase64Transaction(
|
|
40
40
|
createResult.transaction,
|
|
41
41
|
wallet,
|
|
42
|
+
connection,
|
|
42
43
|
);
|
|
43
44
|
console.log('[useCreateGame] Step 2 done. Signature:', signature);
|
|
44
45
|
|
package/src/hooks/useJoinGame.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface JoinGameMutationResult {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function useJoinGame() {
|
|
14
|
-
const { client, wallet } = useDubs();
|
|
14
|
+
const { client, wallet, connection } = useDubs();
|
|
15
15
|
const [status, setStatus] = useState<MutationStatus>('idle');
|
|
16
16
|
const [error, setError] = useState<Error | null>(null);
|
|
17
17
|
const [data, setData] = useState<JoinGameMutationResult | null>(null);
|
|
@@ -39,6 +39,7 @@ export function useJoinGame() {
|
|
|
39
39
|
const signature = await signAndSendBase64Transaction(
|
|
40
40
|
joinResult.transaction,
|
|
41
41
|
wallet,
|
|
42
|
+
connection,
|
|
42
43
|
);
|
|
43
44
|
console.log('[useJoinGame] Step 2 done. Signature:', signature);
|
|
44
45
|
|
package/src/managed-wallet.tsx
CHANGED
|
@@ -156,15 +156,22 @@ export function ManagedWalletProvider({
|
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
// Clear any stale session — Phantom sessions don't survive across app/Phantom restarts.
|
|
160
|
-
// Always require a fresh connect to establish a valid encryption channel.
|
|
161
|
-
console.log(TAG, 'Phantom path — clearing any saved session, will require fresh connect');
|
|
162
|
-
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {});
|
|
163
|
-
|
|
164
159
|
try {
|
|
165
|
-
|
|
160
|
+
const savedSession = await storage.getItem(STORAGE_KEYS.PHANTOM_SESSION);
|
|
161
|
+
if (savedSession && !cancelled) {
|
|
162
|
+
const session: PhantomSession = JSON.parse(savedSession);
|
|
163
|
+
console.log(TAG, 'Found saved Phantom session, restoring for wallet:', session.walletPublicKey);
|
|
164
|
+
phantom.restoreSession(session);
|
|
165
|
+
if (!cancelled) {
|
|
166
|
+
console.log(TAG, 'Phantom reconnected from saved session');
|
|
167
|
+
setConnected(true);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
console.log(TAG, 'No saved Phantom session');
|
|
171
|
+
}
|
|
166
172
|
} catch (err) {
|
|
167
|
-
console.log(TAG, '
|
|
173
|
+
console.log(TAG, 'Phantom session restore failed:', err instanceof Error ? err.message : err);
|
|
174
|
+
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {});
|
|
168
175
|
} finally {
|
|
169
176
|
if (!cancelled) {
|
|
170
177
|
console.log(TAG, 'Phantom init complete, marking ready');
|
package/src/utils/transaction.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Transaction } from '@solana/web3.js';
|
|
1
|
+
import { Transaction, Connection } from '@solana/web3.js';
|
|
2
2
|
import type { WalletAdapter } from '../wallet/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Deserialize a base64-encoded transaction, sign via wallet adapter, send to Solana.
|
|
6
|
+
* Prefers signAndSendTransaction if available (MWA), otherwise falls back to
|
|
7
|
+
* signTransaction + sendRawTransaction via RPC (Phantom deeplinks).
|
|
6
8
|
* Returns the transaction signature.
|
|
7
9
|
*/
|
|
8
10
|
export async function signAndSendBase64Transaction(
|
|
9
11
|
base64Tx: string,
|
|
10
12
|
wallet: WalletAdapter,
|
|
13
|
+
connection: Connection,
|
|
11
14
|
): Promise<string> {
|
|
12
15
|
if (!wallet.publicKey) throw new Error('Wallet not connected');
|
|
13
16
|
|
|
@@ -18,9 +21,13 @@ export async function signAndSendBase64Transaction(
|
|
|
18
21
|
}
|
|
19
22
|
const transaction = Transaction.from(bytes);
|
|
20
23
|
|
|
24
|
+
// Prefer signAndSendTransaction if wallet supports it (e.g. MWA)
|
|
21
25
|
if (wallet.signAndSendTransaction) {
|
|
22
26
|
return wallet.signAndSendTransaction(transaction);
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
// Fallback: sign via wallet, then send via RPC
|
|
30
|
+
const signed = await wallet.signTransaction(transaction);
|
|
31
|
+
const signature = await connection.sendRawTransaction(signed.serialize());
|
|
32
|
+
return signature;
|
|
26
33
|
}
|
|
@@ -237,46 +237,6 @@ export class PhantomDeeplinkAdapter implements WalletAdapter {
|
|
|
237
237
|
return Transaction.from(bs58.decode(data.transaction));
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
async signAndSendTransaction(transaction: Transaction): Promise<string> {
|
|
241
|
-
this.assertConnected();
|
|
242
|
-
console.log(TAG, 'signAndSendTransaction() — serializing transaction');
|
|
243
|
-
|
|
244
|
-
const serializedTx = bs58.encode(
|
|
245
|
-
transaction.serialize({ requireAllSignatures: false, verifySignatures: false }),
|
|
246
|
-
);
|
|
247
|
-
console.log(TAG, 'Transaction serialized, length:', serializedTx.length);
|
|
248
|
-
|
|
249
|
-
const { nonce, ciphertext } = encryptPayload(
|
|
250
|
-
{ transaction: serializedTx, session: this._sessionToken },
|
|
251
|
-
this._sharedSecret!,
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
const requestId = nextRequestId();
|
|
255
|
-
const redirectLink = this.config.redirectUri;
|
|
256
|
-
console.log(TAG, `signAndSendTransaction() requestId=${requestId}`);
|
|
257
|
-
|
|
258
|
-
const params = new URLSearchParams({
|
|
259
|
-
dapp_encryption_public_key: bs58.encode(this._dappKeyPair!.publicKey),
|
|
260
|
-
nonce,
|
|
261
|
-
payload: ciphertext,
|
|
262
|
-
redirect_link: redirectLink,
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const url = `https://phantom.app/ul/v1/signAndSendTransaction?${params.toString()}`;
|
|
266
|
-
console.log(TAG, 'Opening Phantom signAndSendTransaction deeplink...');
|
|
267
|
-
const response = await this.handler.send(url, requestId, this.timeout);
|
|
268
|
-
console.log(TAG, 'Received signAndSendTransaction response');
|
|
269
|
-
|
|
270
|
-
const data = decryptPayload(
|
|
271
|
-
response.params.data,
|
|
272
|
-
response.params.nonce,
|
|
273
|
-
this._sharedSecret!,
|
|
274
|
-
);
|
|
275
|
-
console.log(TAG, 'Transaction sent! Signature:', data.signature);
|
|
276
|
-
|
|
277
|
-
return data.signature as string;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
240
|
async signMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
281
241
|
this.assertConnected();
|
|
282
242
|
console.log(TAG, 'signMessage() — message length:', message.length);
|