@pooflabs/web 0.0.33 → 0.0.35

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.
@@ -11940,11 +11940,6 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
11940
11940
  if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
11941
11941
  Object.assign(headers, _overrides.headers);
11942
11942
  }
11943
- // Signal to backend that client supports offchain transaction signing
11944
- if (typeof window !== "undefined" &&
11945
- window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
11946
- headers["X-Supports-Offchain-Signing"] = "true";
11947
- }
11948
11943
  const requestConfig = {
11949
11944
  method,
11950
11945
  url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
@@ -12327,6 +12322,7 @@ async function setMany(many, options) {
12327
12322
  return transactionResult;
12328
12323
  }
12329
12324
  async function handleOffchainTransaction(tx, authProvider, options) {
12325
+ var _a, _b, _c, _d, _e;
12330
12326
  const config = await getConfig();
12331
12327
  // 1. Sign the transaction message using the auth provider
12332
12328
  const signature = await authProvider.signMessage(tx.message);
@@ -12343,10 +12339,19 @@ async function setMany(many, options) {
12343
12339
  };
12344
12340
  }
12345
12341
  // 4. Submit to RPC endpoint
12346
- const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
12342
+ // Use appId from headers if provided, otherwise fallback to config.appId
12343
+ const appId = ((_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-app-id']) || ((_d = (_c = options === null || options === void 0 ? void 0 : options._overrides) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d['X-App-Id']) || config.appId;
12344
+ const rpcUrl = `${config.apiUrl}/app/${appId}/rpc`;
12345
+ // Build headers, applying overrides if provided
12346
+ const headers = {
12347
+ 'Content-Type': 'application/json',
12348
+ };
12349
+ if ((_e = options === null || options === void 0 ? void 0 : options._overrides) === null || _e === void 0 ? void 0 : _e.headers) {
12350
+ Object.assign(headers, options._overrides.headers);
12351
+ }
12347
12352
  const rpcResponse = await fetch(rpcUrl, {
12348
12353
  method: 'POST',
12349
- headers: { 'Content-Type': 'application/json' },
12354
+ headers,
12350
12355
  body: JSON.stringify({
12351
12356
  jsonrpc: '2.0',
12352
12357
  id: 1,
@@ -12652,7 +12657,7 @@ async function loadDependencies() {
12652
12657
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
12653
12658
  import('react'),
12654
12659
  import('react-dom/client'),
12655
- Promise.resolve().then(function () { return require('./index-DVFbwTxe.js'); })
12660
+ Promise.resolve().then(function () { return require('./index-BLvoqeoa.js'); })
12656
12661
  ]);
12657
12662
  React$1 = reactModule;
12658
12663
  ReactDOM$1 = reactDomModule;
@@ -12763,16 +12768,19 @@ class PhantomWalletProvider {
12763
12768
  isModalOpen: modal.isOpened,
12764
12769
  connectError,
12765
12770
  solana: solana && solanaHook.isAvailable ? {
12766
- signMessage: solana.signMessage,
12767
- signTransaction: solana.signTransaction,
12768
- signAllTransactions: solana.signAllTransactions,
12769
- signAndSendTransaction: solana.signAndSendTransaction,
12770
- getPublicKey: solana.getPublicKey,
12771
+ // Wrap methods to preserve 'this' context - direct references lose binding
12772
+ signMessage: (message) => solana.signMessage(message),
12773
+ signTransaction: (tx) => solana.signTransaction(tx),
12774
+ signAllTransactions: (txs) => solana.signAllTransactions(txs),
12775
+ signAndSendTransaction: (tx) => solana.signAndSendTransaction(tx),
12776
+ getPublicKey: () => solana.getPublicKey(),
12771
12777
  isAvailable: solanaHook.isAvailable,
12778
+ connected: solana.connected,
12779
+ connect: (options) => solana.connect(options),
12772
12780
  } : null,
12773
12781
  };
12774
12782
  }
12775
- }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, solanaHook.isAvailable, connectError]);
12783
+ }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, solana === null || solana === void 0 ? void 0 : solana.connected, solanaHook.isAvailable, connectError]);
12776
12784
  // Auto-login: If connected but no Tarobase session, try to create one.
12777
12785
  // This handles social login callbacks where user returns from OAuth already connected.
12778
12786
  React$1.useEffect(() => {
@@ -12782,8 +12790,8 @@ class PhantomWalletProvider {
12782
12790
  if (!(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) || (phantom === null || phantom === void 0 ? void 0 : phantom.isLoading) || that.loginInProgress || that.autoLoginInProgress || that.pendingLogin) {
12783
12791
  return;
12784
12792
  }
12785
- // Need solana to be available for signing
12786
- if (!solana || !solanaHook.isAvailable) {
12793
+ // Need solana to be available AND connected for signing
12794
+ if (!solana || !solanaHook.isAvailable || !solana.connected) {
12787
12795
  return;
12788
12796
  }
12789
12797
  // Find Solana address
@@ -12829,7 +12837,7 @@ class PhantomWalletProvider {
12829
12837
  }
12830
12838
  };
12831
12839
  autoCreateSession();
12832
- }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, solana, solanaHook.isAvailable, disconnect]);
12840
+ }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, solana, solana === null || solana === void 0 ? void 0 : solana.connected, solanaHook.isAvailable, disconnect]);
12833
12841
  // Handle modal close without connection
12834
12842
  React$1.useEffect(() => {
12835
12843
  // Detect when modal was open and is now closed
@@ -12860,9 +12868,9 @@ class PhantomWalletProvider {
12860
12868
  if (!(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) || !((_a = phantom === null || phantom === void 0 ? void 0 : phantom.addresses) === null || _a === void 0 ? void 0 : _a.length) || !that.pendingLogin || !that.loginInProgress) {
12861
12869
  return;
12862
12870
  }
12863
- // Solana must be available for signing
12864
- // If not ready yet, just return - this effect will re-run when solanaHook.isAvailable changes
12865
- if (!solana || !solanaHook.isAvailable) {
12871
+ // Solana must be available AND connected for signing
12872
+ // If not ready yet, just return - this effect will re-run when solana.connected changes
12873
+ if (!solana || !solanaHook.isAvailable || !solana.connected) {
12866
12874
  return;
12867
12875
  }
12868
12876
  try {
@@ -12917,7 +12925,7 @@ class PhantomWalletProvider {
12917
12925
  }
12918
12926
  };
12919
12927
  handleConnectionSuccess();
12920
- }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, solana, solanaHook.isAvailable]);
12928
+ }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, solana, solana === null || solana === void 0 ? void 0 : solana.connected, solanaHook.isAvailable]);
12921
12929
  return null; // Invisible component
12922
12930
  };
12923
12931
  // Wrapper component with PhantomProvider
@@ -12975,20 +12983,47 @@ class PhantomWalletProvider {
12975
12983
  async ensureSolanaReady() {
12976
12984
  var _a;
12977
12985
  await this.ensureReady();
12978
- // If connected, also wait for solana methods
12986
+ // If connected at the Phantom level, ensure solana methods are ready
12979
12987
  if ((_a = this.phantomMethods) === null || _a === void 0 ? void 0 : _a.isConnected) {
12980
- await new Promise((resolve) => {
12988
+ const timeoutMs = 10000; // 10 second timeout
12989
+ const startTime = Date.now();
12990
+ // First, wait for solana to be available
12991
+ await new Promise((resolve, reject) => {
12981
12992
  const check = () => {
12982
12993
  var _a, _b;
12983
12994
  if ((_b = (_a = this.phantomMethods) === null || _a === void 0 ? void 0 : _a.solana) === null || _b === void 0 ? void 0 : _b.isAvailable) {
12984
12995
  resolve();
12985
12996
  }
12997
+ else if (Date.now() - startTime > timeoutMs) {
12998
+ reject(new Error('Timeout waiting for Solana provider to be available'));
12999
+ }
12986
13000
  else {
12987
13001
  setTimeout(check, 100);
12988
13002
  }
12989
13003
  };
12990
13004
  check();
12991
13005
  });
13006
+ // Now check if the solana provider is connected, if not try to reconnect
13007
+ // Note: We check our wrapper's `connected` which may be stale, but this is just
13008
+ // an optimization to skip reconnect if we know we're already connected.
13009
+ // The actual signing methods use the SDK's bound methods which check live state.
13010
+ if (!this.phantomMethods.solana.connected) {
13011
+ console.log('Solana provider not connected, attempting to reconnect...');
13012
+ try {
13013
+ // onlyIfTrusted: true means it will reconnect silently if previously approved
13014
+ // If not trusted, it will throw and we'll catch it below
13015
+ await this.phantomMethods.solana.connect({ onlyIfTrusted: true });
13016
+ console.log('Solana provider reconnected successfully');
13017
+ }
13018
+ catch (error) {
13019
+ // If onlyIfTrusted fails, the user may need to re-approve via modal
13020
+ console.error('Failed to reconnect solana provider (silent reconnect failed):', error === null || error === void 0 ? void 0 : error.message);
13021
+ throw new Error('Failed to reconnect Solana provider. Please try logging in again.');
13022
+ }
13023
+ }
13024
+ // Note: We don't do a final connected check here because our wrapper's `connected`
13025
+ // is a snapshot that won't update until React re-renders. If connect() succeeded,
13026
+ // the SDK is connected and signing will work.
12992
13027
  }
12993
13028
  }
12994
13029
  /**
@@ -13060,11 +13095,19 @@ class PhantomWalletProvider {
13060
13095
  return (solAddress === null || solAddress === void 0 ? void 0 : solAddress.address) || null;
13061
13096
  }
13062
13097
  async runTransaction(_evmTransactionData, solTransactionData, options) {
13063
- var _a, _b, _c, _d, _e, _f, _g;
13098
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
13064
13099
  if (!solTransactionData) {
13065
13100
  throw new Error("Solana transaction data is required for Phantom wallet");
13066
13101
  }
13067
- await this.ensureSolanaReady();
13102
+ try {
13103
+ await this.ensureSolanaReady();
13104
+ }
13105
+ catch (error) {
13106
+ // Reconnection failed - log user out and throw
13107
+ console.error('Solana provider reconnection failed, logging out:', error.message);
13108
+ await this.logout();
13109
+ throw new Error('Wallet connection lost. Please reconnect.');
13110
+ }
13068
13111
  // Ensure connected
13069
13112
  if (!((_a = this.phantomMethods) === null || _a === void 0 ? void 0 : _a.isConnected)) {
13070
13113
  const user = await this.login();
@@ -13072,7 +13115,14 @@ class PhantomWalletProvider {
13072
13115
  throw new Error('Failed to connect wallet');
13073
13116
  }
13074
13117
  // Wait for solana to be ready after login
13075
- await this.ensureSolanaReady();
13118
+ try {
13119
+ await this.ensureSolanaReady();
13120
+ }
13121
+ catch (error) {
13122
+ console.error('Solana provider reconnection failed after login, logging out:', error.message);
13123
+ await this.logout();
13124
+ throw new Error('Wallet connection lost. Please reconnect.');
13125
+ }
13076
13126
  }
13077
13127
  if (!((_b = this.phantomMethods) === null || _b === void 0 ? void 0 : _b.solana)) {
13078
13128
  throw new Error('Solana signing not available');
@@ -13167,11 +13217,17 @@ class PhantomWalletProvider {
13167
13217
  };
13168
13218
  }
13169
13219
  catch (error) {
13220
+ // Check if this is a connection error - if so, log out
13221
+ if (((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.includes('not connected')) || ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.includes('connect first'))) {
13222
+ console.error('Solana provider connection lost during transaction, logging out');
13223
+ await this.logout();
13224
+ throw new Error('Wallet connection lost. Please reconnect.');
13225
+ }
13170
13226
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
13171
- ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user rejected')) ||
13172
- ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user denied')) ||
13173
- ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user cancelled')) ||
13174
- ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user canceled'));
13227
+ ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user rejected')) ||
13228
+ ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user denied')) ||
13229
+ ((_h = error === null || error === void 0 ? void 0 : error.message) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('user cancelled')) ||
13230
+ ((_j = error === null || error === void 0 ? void 0 : error.message) === null || _j === void 0 ? void 0 : _j.toLowerCase().includes('user canceled'));
13175
13231
  if (!isUserRejection) {
13176
13232
  console.error('Failed to execute transaction', error);
13177
13233
  }
@@ -13179,14 +13235,29 @@ class PhantomWalletProvider {
13179
13235
  }
13180
13236
  }
13181
13237
  async signTransaction(transaction) {
13182
- var _a, _b;
13183
- await this.ensureSolanaReady();
13238
+ var _a, _b, _c, _d;
13239
+ try {
13240
+ await this.ensureSolanaReady();
13241
+ }
13242
+ catch (error) {
13243
+ // Reconnection failed - log user out and throw
13244
+ console.error('Solana provider reconnection failed, logging out:', error.message);
13245
+ await this.logout();
13246
+ throw new Error('Wallet connection lost. Please reconnect.');
13247
+ }
13184
13248
  if (!((_a = this.phantomMethods) === null || _a === void 0 ? void 0 : _a.isConnected)) {
13185
13249
  const user = await this.login();
13186
13250
  if (!user) {
13187
13251
  throw new Error('Failed to connect wallet');
13188
13252
  }
13189
- await this.ensureSolanaReady();
13253
+ try {
13254
+ await this.ensureSolanaReady();
13255
+ }
13256
+ catch (error) {
13257
+ console.error('Solana provider reconnection failed after login, logging out:', error.message);
13258
+ await this.logout();
13259
+ throw new Error('Wallet connection lost. Please reconnect.');
13260
+ }
13190
13261
  }
13191
13262
  if (!((_b = this.phantomMethods) === null || _b === void 0 ? void 0 : _b.solana)) {
13192
13263
  throw new Error('Solana signing not available');
@@ -13195,18 +13266,39 @@ class PhantomWalletProvider {
13195
13266
  return await this.phantomMethods.solana.signTransaction(transaction);
13196
13267
  }
13197
13268
  catch (error) {
13269
+ // Check if this is a connection error - if so, log out
13270
+ if (((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not connected')) || ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.includes('connect first'))) {
13271
+ console.error('Solana provider connection lost during signing, logging out');
13272
+ await this.logout();
13273
+ throw new Error('Wallet connection lost. Please reconnect.');
13274
+ }
13198
13275
  throw new Error(`Failed to sign transaction: ${error.message}`);
13199
13276
  }
13200
13277
  }
13201
13278
  async signMessage(message) {
13202
- var _a, _b, _c, _d, _e, _f;
13203
- await this.ensureSolanaReady();
13279
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13280
+ try {
13281
+ await this.ensureSolanaReady();
13282
+ }
13283
+ catch (error) {
13284
+ // Reconnection failed - log user out and throw
13285
+ console.error('Solana provider reconnection failed, logging out:', error.message);
13286
+ await this.logout();
13287
+ throw new Error('Wallet connection lost. Please reconnect.');
13288
+ }
13204
13289
  if (!((_a = this.phantomMethods) === null || _a === void 0 ? void 0 : _a.isConnected)) {
13205
13290
  const user = await this.login();
13206
13291
  if (!user) {
13207
13292
  throw new Error('Failed to connect wallet');
13208
13293
  }
13209
- await this.ensureSolanaReady();
13294
+ try {
13295
+ await this.ensureSolanaReady();
13296
+ }
13297
+ catch (error) {
13298
+ console.error('Solana provider reconnection failed after login, logging out:', error.message);
13299
+ await this.logout();
13300
+ throw new Error('Wallet connection lost. Please reconnect.');
13301
+ }
13210
13302
  }
13211
13303
  if (!((_b = this.phantomMethods) === null || _b === void 0 ? void 0 : _b.solana)) {
13212
13304
  throw new Error('Solana signing not available');
@@ -13217,11 +13309,17 @@ class PhantomWalletProvider {
13217
13309
  return bufferExports$1.Buffer.from(result.signature).toString('base64');
13218
13310
  }
13219
13311
  catch (error) {
13312
+ // Check if this is a connection error - if so, log out
13313
+ if (((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not connected')) || ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.includes('connect first'))) {
13314
+ console.error('Solana provider connection lost during signing, logging out');
13315
+ await this.logout();
13316
+ throw new Error('Wallet connection lost. Please reconnect.');
13317
+ }
13220
13318
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
13221
- ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes('user rejected')) ||
13222
- ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user denied')) ||
13223
- ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user cancelled')) ||
13224
- ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user canceled'));
13319
+ ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user rejected')) ||
13320
+ ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user denied')) ||
13321
+ ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user cancelled')) ||
13322
+ ((_h = error === null || error === void 0 ? void 0 : error.message) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('user canceled'));
13225
13323
  if (!isUserRejection) {
13226
13324
  console.error('Failed to sign message', error);
13227
13325
  }
@@ -31547,4 +31645,4 @@ exports.setMany = setMany;
31547
31645
  exports.signSessionCreateMessage = signSessionCreateMessage;
31548
31646
  exports.subscribe = subscribe;
31549
31647
  exports.useAuth = useAuth;
31550
- //# sourceMappingURL=index-CyYOGixN.js.map
31648
+ //# sourceMappingURL=index-7EM1gtmw.js.map