@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.js CHANGED
@@ -588,6 +588,28 @@ var ACTION_POLL_MAX_RETRIES = 20;
588
588
  var SIGN_PERMIT2_POLL_MS = 1e3;
589
589
  var SIGN_PERMIT2_MAX_POLLS = 15;
590
590
  var TRANSFER_SIGN_MAX_POLLS = 60;
591
+ function waitForDocumentFocus(timeoutMs = 5e3, intervalMs = 100) {
592
+ return new Promise((resolve, reject) => {
593
+ if (typeof document === "undefined") {
594
+ resolve();
595
+ return;
596
+ }
597
+ if (document.hasFocus()) {
598
+ resolve();
599
+ return;
600
+ }
601
+ const deadline = Date.now() + timeoutMs;
602
+ const timer = setInterval(() => {
603
+ if (document.hasFocus()) {
604
+ clearInterval(timer);
605
+ resolve();
606
+ } else if (Date.now() >= deadline) {
607
+ clearInterval(timer);
608
+ resolve();
609
+ }
610
+ }, intervalMs);
611
+ });
612
+ }
591
613
  function actionSuccess(action, message, data) {
592
614
  return { actionId: action.id, type: action.type, status: "success", message, data };
593
615
  }
@@ -679,6 +701,7 @@ async function createPasskeyCredential(userIdentifier) {
679
701
  const challenge = new Uint8Array(32);
680
702
  crypto.getRandomValues(challenge);
681
703
  const rpId = resolvePasskeyRpId();
704
+ await waitForDocumentFocus();
682
705
  const credential = await navigator.credentials.create({
683
706
  publicKey: {
684
707
  challenge,
@@ -1184,6 +1207,7 @@ function useTransferSigning(pollIntervalMs = 2e3, options) {
1184
1207
  type: "public-key",
1185
1208
  id: base64ToBytes(payload.passkeyCredentialId)
1186
1209
  }] : void 0;
1210
+ await waitForDocumentFocus();
1187
1211
  const assertion = await navigator.credentials.get({
1188
1212
  publicKey: {
1189
1213
  challenge: hashBytes,
@@ -1980,6 +2004,7 @@ function buildProcessingTimeoutMessage(status) {
1980
2004
  return `Payment is taking longer than expected (status: ${status}). Please try again.`;
1981
2005
  }
1982
2006
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
2007
+ var MIN_SEND_AMOUNT_USD = 0.25;
1983
2008
  function isMobile() {
1984
2009
  if (typeof navigator === "undefined") return false;
1985
2010
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
@@ -2305,8 +2330,8 @@ function SwypePayment({
2305
2330
  }, [pendingSelectSourceAction, selectSourceChoices, selectSourceRecommended]);
2306
2331
  const handlePay = useCallback(async () => {
2307
2332
  const parsedAmount = parseFloat(amount);
2308
- if (isNaN(parsedAmount) || parsedAmount <= 0) {
2309
- setError("Enter a valid amount.");
2333
+ if (isNaN(parsedAmount) || parsedAmount < MIN_SEND_AMOUNT_USD) {
2334
+ setError(`Minimum amount is $${MIN_SEND_AMOUNT_USD.toFixed(2)}.`);
2310
2335
  return;
2311
2336
  }
2312
2337
  if (!sourceId) {
@@ -2682,7 +2707,7 @@ function SwypePayment({
2682
2707
  }
2683
2708
  if (step === "enter-amount") {
2684
2709
  const parsedAmount = parseFloat(amount);
2685
- const canContinue = !isNaN(parsedAmount) && parsedAmount > 0;
2710
+ const canContinue = !isNaN(parsedAmount) && parsedAmount >= MIN_SEND_AMOUNT_USD;
2686
2711
  let maxSourceBalance = null;
2687
2712
  for (const acct of accounts) {
2688
2713
  for (const wallet of acct.wallets) {
@@ -2729,7 +2754,7 @@ function SwypePayment({
2729
2754
  "input",
2730
2755
  {
2731
2756
  type: "number",
2732
- min: "0.01",
2757
+ min: MIN_SEND_AMOUNT_USD.toFixed(2),
2733
2758
  step: "0.01",
2734
2759
  value: amount,
2735
2760
  onChange: (e) => setAmount(e.target.value),
@@ -2799,7 +2824,7 @@ function SwypePayment({
2799
2824
  }
2800
2825
  if (step === "ready") {
2801
2826
  const parsedAmount = parseFloat(amount);
2802
- const canPay = !isNaN(parsedAmount) && parsedAmount > 0 && !!sourceId && !loadingData;
2827
+ const canPay = !isNaN(parsedAmount) && parsedAmount >= MIN_SEND_AMOUNT_USD && !!sourceId && !loadingData;
2803
2828
  const noAccounts = !loadingData && accounts.length === 0;
2804
2829
  return /* @__PURE__ */ jsxs("div", { style: cardStyle, children: [
2805
2830
  /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [