@swype-org/react-sdk 0.1.70 → 0.1.73

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
@@ -1644,6 +1644,23 @@ function resolveRestoredMobileFlow(transferStatus, isSetup) {
1644
1644
  }
1645
1645
  return { kind: "resume-open-wallet", step: "open-wallet", clearPersistedFlow: false };
1646
1646
  }
1647
+
1648
+ // src/dataLoading.ts
1649
+ function resolveDataLoadAction({
1650
+ authenticated,
1651
+ step,
1652
+ accountsCount,
1653
+ hasActiveCredential,
1654
+ loading
1655
+ }) {
1656
+ if (!authenticated || step === "login" || step === "otp-verify" || accountsCount > 0 || !hasActiveCredential) {
1657
+ return "reset";
1658
+ }
1659
+ if (loading) {
1660
+ return "wait";
1661
+ }
1662
+ return "load";
1663
+ }
1647
1664
  var FOOTER_CSS = `
1648
1665
  .swype-screen-footer {
1649
1666
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
@@ -2009,11 +2026,17 @@ var METAMASK_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 318.6 3
2009
2026
  <polygon fill="#763D16" stroke="#763D16" stroke-linecap="round" stroke-linejoin="round" points="278.3,114.2 286.8,73.7 274.1,35.5 174.6,109.4 214.9,138.2 267.2,153.5 278.8,140 273.8,136.4 281.8,129.1 275.4,124.1 283.4,118"/>
2010
2027
  <polygon fill="#763D16" stroke="#763D16" stroke-linecap="round" stroke-linejoin="round" points="31.8,73.7 40.3,114.2 35.5,118 43.5,124.1 36.8,129.1 44.8,136.4 39.8,140 51.3,153.5 103.6,138.2 143.1,110.1 44.4,35.5"/>
2011
2028
  </svg>`;
2029
+ var TRUST_WALLET_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 480" fill="none">
2030
+ <rect width="480" height="480" rx="96" fill="#0500FF"/>
2031
+ <path d="M240 97C291.833 133.09 330.903 139.252 378 139.252C378 269.452 346.233 348.948 240 403C133.767 348.948 102 269.452 102 139.252C149.097 139.252 188.167 133.09 240 97Z" stroke="white" stroke-width="30" stroke-linecap="round" stroke-linejoin="round"/>
2032
+ </svg>`;
2012
2033
  var BASE_LOGO = svgToDataUri(BASE_SVG);
2013
2034
  var METAMASK_LOGO = svgToDataUri(METAMASK_SVG);
2035
+ var TRUST_WALLET_LOGO = svgToDataUri(TRUST_WALLET_SVG);
2014
2036
  var KNOWN_LOGOS = {
2015
2037
  metamask: METAMASK_LOGO,
2016
- base: BASE_LOGO
2038
+ base: BASE_LOGO,
2039
+ "trust wallet": TRUST_WALLET_LOGO
2017
2040
  };
2018
2041
  function SourceCard({ name, address, verified, onChangeSource }) {
2019
2042
  const { tokens } = useSwypeConfig();
@@ -4486,6 +4509,7 @@ function SwypePaymentInner({
4486
4509
  const [oneTapLimit, setOneTapLimit] = react.useState(100);
4487
4510
  const [mobileFlow, setMobileFlow] = react.useState(false);
4488
4511
  const [deeplinkUri, setDeeplinkUri] = react.useState(null);
4512
+ const loadingDataRef = react.useRef(false);
4489
4513
  const pollingTransferIdRef = react.useRef(null);
4490
4514
  const mobileSigningTransferIdRef = react.useRef(null);
4491
4515
  const mobileSetupFlowRef = react.useRef(false);
@@ -4516,6 +4540,10 @@ function SwypePaymentInner({
4516
4540
  setConnectingNewAccount(false);
4517
4541
  }
4518
4542
  }, [getAccessToken, activeCredentialId, apiBaseUrl, depositAmount]);
4543
+ const resetDataLoadingState = react.useCallback(() => {
4544
+ loadingDataRef.current = false;
4545
+ setLoadingData(false);
4546
+ }, []);
4519
4547
  const enterPersistedMobileFlow = react.useCallback((persisted, errorMessage) => {
4520
4548
  setMobileFlow(true);
4521
4549
  setDeeplinkUri(persisted.deeplinkUri);
@@ -4533,6 +4561,7 @@ function SwypePaymentInner({
4533
4561
  clearMobileFlowState();
4534
4562
  try {
4535
4563
  await reloadAccounts();
4564
+ resetDataLoadingState();
4536
4565
  setTransfer(null);
4537
4566
  setError(null);
4538
4567
  setDeeplinkUri(null);
@@ -4553,7 +4582,7 @@ function SwypePaymentInner({
4553
4582
  setDeeplinkUri(null);
4554
4583
  setMobileFlow(false);
4555
4584
  setStep("confirm-sign");
4556
- }, [polling.stopPolling, reloadAccounts]);
4585
+ }, [polling.stopPolling, reloadAccounts, resetDataLoadingState]);
4557
4586
  const handleRetryMobileStatus = react.useCallback(() => {
4558
4587
  setError(null);
4559
4588
  const currentTransfer = polling.transfer ?? transfer;
@@ -4587,8 +4616,9 @@ function SwypePaymentInner({
4587
4616
  const activeOtpStatus = verificationTarget?.kind === "email" ? emailLoginState.status : verificationTarget?.kind === "phone" ? smsLoginState.status : "initial";
4588
4617
  const activeOtpErrorMessage = verificationTarget?.kind === "email" && emailLoginState.status === "error" ? emailLoginState.error?.message ?? "Failed to continue with email." : verificationTarget?.kind === "phone" && smsLoginState.status === "error" ? smsLoginState.error?.message ?? "Failed to continue with phone number." : null;
4589
4618
  react.useEffect(() => {
4619
+ if (authenticated) return;
4590
4620
  if (activeOtpErrorMessage) setError(activeOtpErrorMessage);
4591
- }, [activeOtpErrorMessage]);
4621
+ }, [activeOtpErrorMessage, authenticated]);
4592
4622
  const handleSendLoginCode = react.useCallback(async () => {
4593
4623
  const normalizedIdentifier = normalizeAuthIdentifier(authInput);
4594
4624
  if (!normalizedIdentifier) {
@@ -4781,12 +4811,26 @@ function SwypePaymentInner({
4781
4811
  handleAuthorizedMobileReturn,
4782
4812
  onComplete
4783
4813
  ]);
4784
- const loadingDataRef = react.useRef(false);
4785
4814
  react.useEffect(() => {
4786
- if (!authenticated) return;
4787
- if (step === "login" || step === "otp-verify") return;
4788
- if (accounts.length > 0 || loadingDataRef.current) return;
4789
- if (!activeCredentialId) return;
4815
+ const loadAction = resolveDataLoadAction({
4816
+ authenticated,
4817
+ step,
4818
+ accountsCount: accounts.length,
4819
+ hasActiveCredential: !!activeCredentialId,
4820
+ loading: loadingDataRef.current
4821
+ });
4822
+ if (loadAction === "reset") {
4823
+ resetDataLoadingState();
4824
+ return;
4825
+ }
4826
+ if (loadAction === "wait") {
4827
+ return;
4828
+ }
4829
+ const credentialId = activeCredentialId;
4830
+ if (!credentialId) {
4831
+ resetDataLoadingState();
4832
+ return;
4833
+ }
4790
4834
  let cancelled = false;
4791
4835
  loadingDataRef.current = true;
4792
4836
  const load = async () => {
@@ -4797,7 +4841,7 @@ function SwypePaymentInner({
4797
4841
  if (!token) throw new Error("Not authenticated");
4798
4842
  const [prov, accts, chn] = await Promise.all([
4799
4843
  fetchProviders(apiBaseUrl, token),
4800
- fetchAccounts(apiBaseUrl, token, activeCredentialId),
4844
+ fetchAccounts(apiBaseUrl, token, credentialId),
4801
4845
  fetchChains(apiBaseUrl, token)
4802
4846
  ]);
4803
4847
  if (cancelled) return;
@@ -4835,8 +4879,7 @@ function SwypePaymentInner({
4835
4879
  }
4836
4880
  } finally {
4837
4881
  if (!cancelled) {
4838
- setLoadingData(false);
4839
- loadingDataRef.current = false;
4882
+ resetDataLoadingState();
4840
4883
  }
4841
4884
  }
4842
4885
  };
@@ -4845,7 +4888,7 @@ function SwypePaymentInner({
4845
4888
  cancelled = true;
4846
4889
  loadingDataRef.current = false;
4847
4890
  };
4848
- }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount]);
4891
+ }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount, resetDataLoadingState]);
4849
4892
  react.useEffect(() => {
4850
4893
  if (!polling.transfer) return;
4851
4894
  if (polling.transfer.status === "COMPLETED") {