@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.js CHANGED
@@ -151,6 +151,12 @@ var SOLANA_PROGRAM_ERRORS = {
151
151
  6048: { code: "no_survivors_to_distribute", message: "No survivors to distribute winnings to" },
152
152
  6049: { code: "too_many_survivors", message: "Too many survivors (max 50 per batch)" }
153
153
  };
154
+ var WALLET_ERROR_PATTERNS = [
155
+ { pattern: /CancellationException/i, error: { code: "transaction_rejected", message: "Transaction was rejected by the wallet" } },
156
+ { pattern: /declined/i, error: { code: "user_declined", message: "Transaction was declined" } },
157
+ { pattern: /timeout/i, error: { code: "transaction_timeout", message: "Transaction timed out" } },
158
+ { pattern: /not connected/i, error: { code: "wallet_not_connected", message: "Wallet is not connected" } }
159
+ ];
154
160
  var SOLANA_BUILTIN_ERRORS = {
155
161
  0: { code: "generic_error", message: "Generic instruction error" },
156
162
  1: { code: "invalid_argument", message: "Invalid argument passed to program" },
@@ -167,6 +173,9 @@ function parseSolanaError(err) {
167
173
  if (!err) return { code: "unknown_error", message: "Unknown transaction error" };
168
174
  let parsed = err;
169
175
  if (typeof parsed === "string") {
176
+ for (const { pattern, error } of WALLET_ERROR_PATTERNS) {
177
+ if (pattern.test(parsed)) return error;
178
+ }
170
179
  try {
171
180
  const jsonMatch = parsed.match(/\{.*\}/s);
172
181
  if (jsonMatch) parsed = JSON.parse(jsonMatch[0]);
@@ -1881,6 +1890,23 @@ function useClaim() {
1881
1890
  console.error("[useClaim] FAILED:", err);
1882
1891
  const raw = err instanceof Error ? err.message : String(err);
1883
1892
  const parsed = parseSolanaError(raw);
1893
+ if (parsed.code === "transaction_rejected" || parsed.code === "transaction_failed") {
1894
+ try {
1895
+ const game = await client.getGame(params.gameId);
1896
+ const myBet = game.bettors?.find(
1897
+ (b) => b.wallet === params.playerWallet
1898
+ );
1899
+ if (myBet?.amountClaimed != null && myBet.amountClaimed > 0) {
1900
+ const claimedErr = new Error("Player has already claimed their winnings");
1901
+ claimedErr.code = "already_claimed";
1902
+ setError(claimedErr);
1903
+ setStatus("error");
1904
+ throw claimedErr;
1905
+ }
1906
+ } catch (checkErr) {
1907
+ if (checkErr?.code === "already_claimed") throw checkErr;
1908
+ }
1909
+ }
1884
1910
  const error2 = new Error(parsed.message);
1885
1911
  error2.code = parsed.code;
1886
1912
  setError(error2);