@liberfi.io/react-predict 0.3.48 → 0.3.50

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
@@ -519,8 +519,9 @@ var PredictClient = class {
519
519
  // Redeem (resolved market token redemption)
520
520
  // -------------------------------------------------------------------------
521
521
  /**
522
- * Prepare EIP-712 SafeTx typed data for a Polymarket redeem transaction.
523
- * The frontend must sign this data and pass the signature to `redeemPolymarket`.
522
+ * Prepare the signing payload for a Polymarket redeem transaction.
523
+ * The frontend must sign the returned Safe hash or deposit-wallet typed data
524
+ * and pass the signature to `redeemPolymarket`.
524
525
  *
525
526
  * Maps to `POST /api/v1/redeem/polymarket/prepare`.
526
527
  */
@@ -530,7 +531,7 @@ var PredictClient = class {
530
531
  }
531
532
  /**
532
533
  * Redeem tokens from a resolved Polymarket market via gasless Relayer.
533
- * Requires a valid EIP-712 signature from the prepare step.
534
+ * Requires a valid signature for the payload returned by the prepare step.
534
535
  *
535
536
  * Maps to `POST /api/v1/redeem/polymarket`.
536
537
  */
@@ -1941,21 +1942,51 @@ function useRedeemPosition() {
1941
1942
  wallet_address,
1942
1943
  condition_id,
1943
1944
  neg_risk,
1944
- signMessage
1945
+ signMessage,
1946
+ signTypedData
1945
1947
  }) => {
1946
1948
  const prepared = await client.prepareRedeemPolymarket({
1947
1949
  wallet_address,
1948
1950
  condition_id,
1949
1951
  neg_risk
1950
1952
  });
1951
- const signature = await signMessage(prepared.message_hash);
1952
- return client.redeemPolymarket({
1953
+ const walletKind = prepared.wallet_kind ?? "safe";
1954
+ let signature;
1955
+ if (walletKind === "deposit") {
1956
+ if (!prepared.typed_data) {
1957
+ throw new Error("Redeem prepare response missing typed_data");
1958
+ }
1959
+ if (!prepared.deadline) {
1960
+ throw new Error("Redeem prepare response missing deadline");
1961
+ }
1962
+ if (!signTypedData) {
1963
+ throw new Error("Deposit wallet redeem requires signTypedData");
1964
+ }
1965
+ signature = await signTypedData(prepared.typed_data);
1966
+ } else {
1967
+ if (!prepared.message_hash) {
1968
+ throw new Error("Redeem prepare response missing message_hash");
1969
+ }
1970
+ signature = await signMessage(prepared.message_hash);
1971
+ }
1972
+ const result = await client.redeemPolymarket({
1953
1973
  wallet_address,
1954
1974
  condition_id,
1955
1975
  neg_risk,
1956
1976
  signature,
1957
- nonce: prepared.nonce
1977
+ nonce: prepared.nonce,
1978
+ wallet_kind: walletKind,
1979
+ deadline: prepared.deadline
1958
1980
  });
1981
+ if (result.status === "STATE_FAILED" || result.status === "STATE_INVALID") {
1982
+ throw new Error(`Redeem transaction ${result.status}`);
1983
+ }
1984
+ if (result.status !== "STATE_MINED" && result.status !== "STATE_CONFIRMED") {
1985
+ throw new Error(
1986
+ `Redeem transaction not settled yet (${result.status})`
1987
+ );
1988
+ }
1989
+ return result;
1959
1990
  },
1960
1991
  onSuccess: () => {
1961
1992
  queryClient.invalidateQueries({ queryKey: ["predict", "positions"] });