@swype-org/react-sdk 0.1.14 → 0.1.15

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.cjs CHANGED
@@ -591,6 +591,28 @@ var ACTION_POLL_MAX_RETRIES = 20;
591
591
  var SIGN_PERMIT2_POLL_MS = 1e3;
592
592
  var SIGN_PERMIT2_MAX_POLLS = 15;
593
593
  var TRANSFER_SIGN_MAX_POLLS = 60;
594
+ function waitForDocumentFocus(timeoutMs = 5e3, intervalMs = 100) {
595
+ return new Promise((resolve, reject) => {
596
+ if (typeof document === "undefined") {
597
+ resolve();
598
+ return;
599
+ }
600
+ if (document.hasFocus()) {
601
+ resolve();
602
+ return;
603
+ }
604
+ const deadline = Date.now() + timeoutMs;
605
+ const timer = setInterval(() => {
606
+ if (document.hasFocus()) {
607
+ clearInterval(timer);
608
+ resolve();
609
+ } else if (Date.now() >= deadline) {
610
+ clearInterval(timer);
611
+ resolve();
612
+ }
613
+ }, intervalMs);
614
+ });
615
+ }
594
616
  function actionSuccess(action, message, data) {
595
617
  return { actionId: action.id, type: action.type, status: "success", message, data };
596
618
  }
@@ -682,6 +704,7 @@ async function createPasskeyCredential(userIdentifier) {
682
704
  const challenge = new Uint8Array(32);
683
705
  crypto.getRandomValues(challenge);
684
706
  const rpId = resolvePasskeyRpId();
707
+ await waitForDocumentFocus();
685
708
  const credential = await navigator.credentials.create({
686
709
  publicKey: {
687
710
  challenge,
@@ -1187,6 +1210,7 @@ function useTransferSigning(pollIntervalMs = 2e3, options) {
1187
1210
  type: "public-key",
1188
1211
  id: base64ToBytes(payload.passkeyCredentialId)
1189
1212
  }] : void 0;
1213
+ await waitForDocumentFocus();
1190
1214
  const assertion = await navigator.credentials.get({
1191
1215
  publicKey: {
1192
1216
  challenge: hashBytes,
@@ -1983,6 +2007,7 @@ function buildProcessingTimeoutMessage(status) {
1983
2007
  return `Payment is taking longer than expected (status: ${status}). Please try again.`;
1984
2008
  }
1985
2009
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
2010
+ var MIN_SEND_AMOUNT_USD = 0.25;
1986
2011
  function isMobile() {
1987
2012
  if (typeof navigator === "undefined") return false;
1988
2013
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
@@ -2308,8 +2333,8 @@ function SwypePayment({
2308
2333
  }, [pendingSelectSourceAction, selectSourceChoices, selectSourceRecommended]);
2309
2334
  const handlePay = react.useCallback(async () => {
2310
2335
  const parsedAmount = parseFloat(amount);
2311
- if (isNaN(parsedAmount) || parsedAmount <= 0) {
2312
- setError("Enter a valid amount.");
2336
+ if (isNaN(parsedAmount) || parsedAmount < MIN_SEND_AMOUNT_USD) {
2337
+ setError(`Minimum amount is $${MIN_SEND_AMOUNT_USD.toFixed(2)}.`);
2313
2338
  return;
2314
2339
  }
2315
2340
  if (!sourceId) {
@@ -2685,7 +2710,7 @@ function SwypePayment({
2685
2710
  }
2686
2711
  if (step === "enter-amount") {
2687
2712
  const parsedAmount = parseFloat(amount);
2688
- const canContinue = !isNaN(parsedAmount) && parsedAmount > 0;
2713
+ const canContinue = !isNaN(parsedAmount) && parsedAmount >= MIN_SEND_AMOUNT_USD;
2689
2714
  let maxSourceBalance = null;
2690
2715
  for (const acct of accounts) {
2691
2716
  for (const wallet of acct.wallets) {
@@ -2732,7 +2757,7 @@ function SwypePayment({
2732
2757
  "input",
2733
2758
  {
2734
2759
  type: "number",
2735
- min: "0.01",
2760
+ min: MIN_SEND_AMOUNT_USD.toFixed(2),
2736
2761
  step: "0.01",
2737
2762
  value: amount,
2738
2763
  onChange: (e) => setAmount(e.target.value),
@@ -2802,7 +2827,7 @@ function SwypePayment({
2802
2827
  }
2803
2828
  if (step === "ready") {
2804
2829
  const parsedAmount = parseFloat(amount);
2805
- const canPay = !isNaN(parsedAmount) && parsedAmount > 0 && !!sourceId && !loadingData;
2830
+ const canPay = !isNaN(parsedAmount) && parsedAmount >= MIN_SEND_AMOUNT_USD && !!sourceId && !loadingData;
2806
2831
  const noAccounts = !loadingData && accounts.length === 0;
2807
2832
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: cardStyle, children: [
2808
2833
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [