@pollar/react 0.10.1-rc.10 → 0.10.1-rc.11

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
@@ -1033,7 +1033,7 @@ var PollarModalFooter = () => {
1033
1033
  /* @__PURE__ */ jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
1034
1034
  /* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
1035
1035
  "v",
1036
- "0.10.1-rc.10"
1036
+ "0.10.1-rc.11"
1037
1037
  ] })
1038
1038
  ] })
1039
1039
  ] });
@@ -3427,6 +3427,7 @@ function AssetSelect({
3427
3427
  options,
3428
3428
  onChange,
3429
3429
  loading = false,
3430
+ loadingLabel,
3430
3431
  disabled = false,
3431
3432
  appGroupLabel = "App assets",
3432
3433
  otherGroupLabel = "Other assets",
@@ -3436,7 +3437,10 @@ function AssetSelect({
3436
3437
  const otherAssets = options.filter((o) => !o.enabledInApp);
3437
3438
  return /* @__PURE__ */ jsxs("div", { className: "pollar-send-field", children: [
3438
3439
  /* @__PURE__ */ jsx("label", { className: "pollar-send-label", children: label }),
3439
- loading ? /* @__PURE__ */ jsx("div", { className: "pollar-send-skeleton" }) : /* @__PURE__ */ jsxs(
3440
+ loading ? loadingLabel ? /* @__PURE__ */ jsxs("div", { className: "pollar-input pollar-select-loading", children: [
3441
+ /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm" }),
3442
+ /* @__PURE__ */ jsx("span", { children: loadingLabel })
3443
+ ] }) : /* @__PURE__ */ jsx("div", { className: "pollar-send-skeleton" }) : /* @__PURE__ */ jsxs(
3440
3444
  "select",
3441
3445
  {
3442
3446
  className: "pollar-input pollar-send-select",
@@ -4109,10 +4113,6 @@ function SwapModalTemplate({
4109
4113
  /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })
4110
4114
  ] })
4111
4115
  ] }),
4112
- step === "form" && configLoading && /* @__PURE__ */ jsxs("div", { className: "pollar-loading-block", children: [
4113
- /* @__PURE__ */ jsx("div", { className: "pollar-spinner" }),
4114
- /* @__PURE__ */ jsx("span", { children: "Loading swap options\u2026" })
4115
- ] }),
4116
4116
  step === "form" && !configLoading && swapUnavailable && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: "Swap is not available for this app." }),
4117
4117
  step === "form" && !swapUnavailable && /* @__PURE__ */ jsxs(Fragment, { children: [
4118
4118
  smartUnsupported && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: "Swaps are not yet available for smart (passkey) wallets." }),
@@ -4121,7 +4121,8 @@ function SwapModalTemplate({
4121
4121
  {
4122
4122
  label: "You pay",
4123
4123
  value: sellKey,
4124
- loading: isLoadingData,
4124
+ loading: isLoadingData || configLoading,
4125
+ loadingLabel: "Loading assets\u2026",
4125
4126
  disabled: configLoading,
4126
4127
  options: sellOptions.map((o) => ({
4127
4128
  key: assetOptionKey(o),
@@ -4163,7 +4164,8 @@ function SwapModalTemplate({
4163
4164
  {
4164
4165
  label: "You receive",
4165
4166
  value: buyKey,
4166
- loading: isLoadingData,
4167
+ loading: isLoadingData || configLoading,
4168
+ loadingLabel: "Loading assets\u2026",
4167
4169
  disabled: configLoading,
4168
4170
  options: buyOptions.map((o) => ({
4169
4171
  key: assetOptionKey(o),
@@ -4594,6 +4596,8 @@ function EarnModal({ onClose }) {
4594
4596
  earnWithdraw,
4595
4597
  tx: transaction,
4596
4598
  wallet,
4599
+ walletBalance,
4600
+ refreshWalletBalance,
4597
4601
  network,
4598
4602
  styles
4599
4603
  } = usePollar();
@@ -4625,6 +4629,9 @@ function EarnModal({ onClose }) {
4625
4629
  useEffect(() => {
4626
4630
  void loadProviders();
4627
4631
  }, [loadProviders]);
4632
+ useEffect(() => {
4633
+ void refreshWalletBalance();
4634
+ }, [refreshWalletBalance]);
4628
4635
  useEffect(() => {
4629
4636
  if (!provider) return;
4630
4637
  let cancelled = false;
@@ -4668,6 +4675,15 @@ function EarnModal({ onClose }) {
4668
4675
  const withdrawUnit = position?.withdrawUnit ?? "asset";
4669
4676
  const assetCode = selectedOpportunity?.asset.code ?? "";
4670
4677
  const amountUnitLabel = tab === "deposit" ? assetCode : withdrawUnit === "shares" ? "shares" : assetCode;
4678
+ const walletAvailable = (() => {
4679
+ if (!selectedOpportunity) return null;
4680
+ const balances = walletBalance.step === "loaded" ? walletBalance.data.balances : [];
4681
+ const issuer = selectedOpportunity.asset.issuer;
4682
+ const rec = balances.find(
4683
+ (b) => issuer === null ? b.type === "native" : b.code === assetCode && b.issuer === issuer
4684
+ );
4685
+ return rec ? rec.available : null;
4686
+ })();
4671
4687
  const hash = transaction.step === "success" ? transaction.hash : null;
4672
4688
  const buildData = "buildData" in transaction ? transaction.buildData : null;
4673
4689
  const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
@@ -4675,7 +4691,9 @@ function EarnModal({ onClose }) {
4675
4691
  const isInProgress = IN_FLIGHT_STEPS2.includes(transaction.step);
4676
4692
  const showBack = step === "tx" && (transaction.step === "error" || transaction.step === "success") && !isInProgress;
4677
4693
  const txTitle = isInProgress ? tab === "deposit" ? "Depositing\u2026" : "Withdrawing\u2026" : transaction.step === "success" ? "Done!" : transaction.step === "error" ? tab === "deposit" ? "Deposit failed" : "Withdraw failed" : "Confirm";
4678
- const canSubmit = !smartUnsupported && !!provider && !!opportunityId && !!amount && parseFloat(amount) > 0 && !providersLoading && !loadingOpps;
4694
+ const parsedAmount = parseFloat(amount);
4695
+ const exceedsAvailable = tab === "deposit" ? walletAvailable != null && parsedAmount > parseFloat(walletAvailable) : position != null && parsedAmount > parseFloat(position.withdrawable);
4696
+ const canSubmit = !smartUnsupported && !!provider && !!opportunityId && !!amount && parsedAmount > 0 && !exceedsAvailable && !providersLoading && !loadingOpps;
4679
4697
  const cssVars = {
4680
4698
  "--pollar-accent": accentColor,
4681
4699
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
@@ -4708,6 +4726,10 @@ function EarnModal({ onClose }) {
4708
4726
  setFormError("Enter a valid amount");
4709
4727
  return;
4710
4728
  }
4729
+ if (tab === "deposit" && walletAvailable != null && parsed > parseFloat(walletAvailable)) {
4730
+ setFormError("Amount exceeds your wallet balance");
4731
+ return;
4732
+ }
4711
4733
  if (tab === "withdraw" && position && parsed > parseFloat(position.withdrawable)) {
4712
4734
  setFormError("Amount exceeds your position");
4713
4735
  return;
@@ -4747,6 +4769,7 @@ function EarnModal({ onClose }) {
4747
4769
  if (refreshing || !provider) return;
4748
4770
  setRefreshing(true);
4749
4771
  try {
4772
+ void refreshWalletBalance();
4750
4773
  const opps = await getEarnOpportunities(provider);
4751
4774
  setOpportunities(opps);
4752
4775
  setOpportunityId((cur) => opps.some((o) => o.id === cur) ? cur : opps[0]?.id ?? "");
@@ -4874,6 +4897,14 @@ function EarnModal({ onClose }) {
4874
4897
  )
4875
4898
  ] }),
4876
4899
  selectedOpportunity && /* @__PURE__ */ jsxs("div", { className: "pollar-swap-quote", children: [
4900
+ tab === "deposit" && /* @__PURE__ */ jsxs("div", { className: "pollar-swap-quote-row", children: [
4901
+ /* @__PURE__ */ jsx("span", { className: "pollar-send-hint", children: "In your wallet" }),
4902
+ /* @__PURE__ */ jsxs("span", { children: [
4903
+ walletAvailable != null ? formatAmount4(walletAvailable) : "\u2026",
4904
+ " ",
4905
+ assetCode
4906
+ ] })
4907
+ ] }),
4877
4908
  /* @__PURE__ */ jsxs("div", { className: "pollar-swap-quote-row", children: [
4878
4909
  /* @__PURE__ */ jsx("span", { className: "pollar-send-hint", children: "Your position" }),
4879
4910
  /* @__PURE__ */ jsxs("span", { children: [
@@ -4893,6 +4924,12 @@ function EarnModal({ onClose }) {
4893
4924
  /* @__PURE__ */ jsxs("div", { className: "pollar-send-field", children: [
4894
4925
  /* @__PURE__ */ jsxs("div", { className: "pollar-send-label-row", children: [
4895
4926
  /* @__PURE__ */ jsx("label", { className: "pollar-send-label", children: tab === "deposit" ? "Amount" : "Withdraw amount" }),
4927
+ tab === "deposit" && walletAvailable != null && /* @__PURE__ */ jsxs("button", { type: "button", className: "pollar-swap-custom-toggle", onClick: () => setAmount(walletAvailable), children: [
4928
+ "Max: ",
4929
+ formatAmount4(walletAvailable),
4930
+ " ",
4931
+ amountUnitLabel
4932
+ ] }),
4896
4933
  tab === "withdraw" && position && /* @__PURE__ */ jsxs("button", { type: "button", className: "pollar-swap-custom-toggle", onClick: () => setAmount(position.withdrawable), children: [
4897
4934
  "Max: ",
4898
4935
  formatAmount4(position.withdrawable),
@@ -5868,6 +5905,9 @@ function PollarProvider({
5868
5905
  const [sendModalOpen, setSendModalOpen] = useState(false);
5869
5906
  const [swapModalOpen, setSwapModalOpen] = useState(false);
5870
5907
  const [earnModalOpen, setEarnModalOpen] = useState(false);
5908
+ const [sendModalKey, setSendModalKey] = useState(0);
5909
+ const [swapModalKey, setSwapModalKey] = useState(0);
5910
+ const [earnModalKey, setEarnModalKey] = useState(0);
5871
5911
  const [receiveModalOpen, setReceiveModalOpen] = useState(false);
5872
5912
  const [sessionsModalOpen, setSessionsModalOpen] = useState(false);
5873
5913
  const [distributionRulesModalOpen, setDistributionRulesModalOpen] = useState(false);
@@ -5910,21 +5950,33 @@ function PollarProvider({
5910
5950
  setTrustline: (asset, opts) => pollarClient.setTrustline(asset, opts),
5911
5951
  openEnabledAssetsModal: () => setEnabledAssetsModalOpen(true),
5912
5952
  // send / receive
5913
- openSendModal: () => setSendModalOpen(true),
5953
+ openSendModal: () => {
5954
+ pollarClient.resetTransactionState();
5955
+ setSendModalKey((k) => k + 1);
5956
+ setSendModalOpen(true);
5957
+ },
5914
5958
  openReceiveModal: () => setReceiveModalOpen(true),
5915
5959
  // swap
5916
5960
  getSwapConfig: () => pollarClient.getSwapConfig(),
5917
5961
  getSwapTokens: () => pollarClient.getSwapTokens(),
5918
5962
  getSwapQuote: (params) => pollarClient.getSwapQuote(params),
5919
5963
  swap: (quote, opts) => pollarClient.swap(quote, opts),
5920
- openSwapModal: () => setSwapModalOpen(true),
5964
+ openSwapModal: () => {
5965
+ pollarClient.resetTransactionState();
5966
+ setSwapModalKey((k) => k + 1);
5967
+ setSwapModalOpen(true);
5968
+ },
5921
5969
  // earn
5922
5970
  getEarnProviders: () => pollarClient.getEarnProviders(),
5923
5971
  getEarnOpportunities: (provider) => pollarClient.getEarnOpportunities(provider),
5924
5972
  getEarnPosition: (params) => pollarClient.getEarnPosition(params),
5925
5973
  earnDeposit: (params) => pollarClient.earnDeposit(params),
5926
5974
  earnWithdraw: (params) => pollarClient.earnWithdraw(params),
5927
- openEarnModal: () => setEarnModalOpen(true),
5975
+ openEarnModal: () => {
5976
+ pollarClient.resetTransactionState();
5977
+ setEarnModalKey((k) => k + 1);
5978
+ setEarnModalOpen(true);
5979
+ },
5928
5980
  // sessions
5929
5981
  sessions,
5930
5982
  openSessionsModal: () => setSessionsModalOpen(true),
@@ -5978,9 +6030,9 @@ function PollarProvider({
5978
6030
  txHistoryModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setTxHistoryModalOpen(false), children: /* @__PURE__ */ jsx(TxHistoryModal, { onClose: () => setTxHistoryModalOpen(false) }) }),
5979
6031
  walletBalanceModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setWalletBalanceModalOpen(false), children: /* @__PURE__ */ jsx(WalletBalanceModal, { onClose: () => setWalletBalanceModalOpen(false) }) }),
5980
6032
  enabledAssetsModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setEnabledAssetsModalOpen(false), children: /* @__PURE__ */ jsx(EnabledAssetsModal, { onClose: () => setEnabledAssetsModalOpen(false) }) }),
5981
- sendModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsx(SendModal, { onClose: () => setSendModalOpen(false) }) }),
5982
- swapModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsx(SwapModal, { onClose: () => setSwapModalOpen(false) }) }),
5983
- earnModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setEarnModalOpen(false), children: /* @__PURE__ */ jsx(EarnModal, { onClose: () => setEarnModalOpen(false) }) }),
6033
+ sendModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsx(SendModal, { onClose: () => setSendModalOpen(false) }) }, sendModalKey),
6034
+ swapModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsx(SwapModal, { onClose: () => setSwapModalOpen(false) }) }, swapModalKey),
6035
+ earnModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setEarnModalOpen(false), children: /* @__PURE__ */ jsx(EarnModal, { onClose: () => setEarnModalOpen(false) }) }, earnModalKey),
5984
6036
  receiveModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false) }) }),
5985
6037
  sessionsModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSessionsModalOpen(false), children: /* @__PURE__ */ jsx(SessionsModal, { onClose: () => setSessionsModalOpen(false) }) }),
5986
6038
  distributionRulesModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setDistributionRulesModalOpen(false), children: /* @__PURE__ */ jsx(DistributionRulesModal, { onClose: () => setDistributionRulesModalOpen(false) }) })