@dubsdotapp/expo 0.2.34 → 0.2.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.
package/dist/index.mjs CHANGED
@@ -82,6 +82,12 @@ var SOLANA_PROGRAM_ERRORS = {
82
82
  6048: { code: "no_survivors_to_distribute", message: "No survivors to distribute winnings to" },
83
83
  6049: { code: "too_many_survivors", message: "Too many survivors (max 50 per batch)" }
84
84
  };
85
+ var WALLET_ERROR_PATTERNS = [
86
+ { pattern: /CancellationException/i, error: { code: "transaction_rejected", message: "Transaction was rejected by the wallet" } },
87
+ { pattern: /declined/i, error: { code: "user_declined", message: "Transaction was declined" } },
88
+ { pattern: /timeout/i, error: { code: "transaction_timeout", message: "Transaction timed out" } },
89
+ { pattern: /not connected/i, error: { code: "wallet_not_connected", message: "Wallet is not connected" } }
90
+ ];
85
91
  var SOLANA_BUILTIN_ERRORS = {
86
92
  0: { code: "generic_error", message: "Generic instruction error" },
87
93
  1: { code: "invalid_argument", message: "Invalid argument passed to program" },
@@ -98,6 +104,9 @@ function parseSolanaError(err) {
98
104
  if (!err) return { code: "unknown_error", message: "Unknown transaction error" };
99
105
  let parsed = err;
100
106
  if (typeof parsed === "string") {
107
+ for (const { pattern, error } of WALLET_ERROR_PATTERNS) {
108
+ if (pattern.test(parsed)) return error;
109
+ }
101
110
  try {
102
111
  const jsonMatch = parsed.match(/\{.*\}/s);
103
112
  if (jsonMatch) parsed = JSON.parse(jsonMatch[0]);
@@ -1832,6 +1841,23 @@ function useClaim() {
1832
1841
  console.error("[useClaim] FAILED:", err);
1833
1842
  const raw = err instanceof Error ? err.message : String(err);
1834
1843
  const parsed = parseSolanaError(raw);
1844
+ if (parsed.code === "transaction_rejected" || parsed.code === "transaction_failed") {
1845
+ try {
1846
+ const game = await client.getGame(params.gameId);
1847
+ const myBet = game.bettors?.find(
1848
+ (b) => b.wallet === params.playerWallet
1849
+ );
1850
+ if (myBet?.amountClaimed != null && myBet.amountClaimed > 0) {
1851
+ const claimedErr = new Error("Player has already claimed their winnings");
1852
+ claimedErr.code = "already_claimed";
1853
+ setError(claimedErr);
1854
+ setStatus("error");
1855
+ throw claimedErr;
1856
+ }
1857
+ } catch (checkErr) {
1858
+ if (checkErr?.code === "already_claimed") throw checkErr;
1859
+ }
1860
+ }
1835
1861
  const error2 = new Error(parsed.message);
1836
1862
  error2.code = parsed.code;
1837
1863
  setError(error2);