@loafmarkets/ui 0.1.13 → 0.1.14

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.d.mts CHANGED
@@ -663,8 +663,12 @@ type PropertyBuyProps = {
663
663
  isAuthenticated: boolean;
664
664
  onSignIn: () => void;
665
665
  saleData?: SaleData | null;
666
+ walletUsdcBalance?: number | null;
667
+ onPurchase?: (tokenAmount: number) => Promise<void>;
668
+ purchaseStatus?: 'idle' | 'checking-allowance' | 'approving' | 'purchasing' | 'success' | 'error';
669
+ purchaseError?: string | null;
666
670
  };
667
- declare function PropertyBuy({ propertyName, propertyLocation: propertyLocationLabel, isAuthenticated, onSignIn, saleData, }: PropertyBuyProps): react_jsx_runtime.JSX.Element;
671
+ declare function PropertyBuy({ propertyName, propertyLocation: propertyLocationLabel, isAuthenticated, onSignIn, saleData, walletUsdcBalance, onPurchase, purchaseStatus, purchaseError, }: PropertyBuyProps): react_jsx_runtime.JSX.Element;
668
672
 
669
673
  type OwnerBookingProps = {
670
674
  propertyName?: string | null;
package/dist/index.d.ts CHANGED
@@ -663,8 +663,12 @@ type PropertyBuyProps = {
663
663
  isAuthenticated: boolean;
664
664
  onSignIn: () => void;
665
665
  saleData?: SaleData | null;
666
+ walletUsdcBalance?: number | null;
667
+ onPurchase?: (tokenAmount: number) => Promise<void>;
668
+ purchaseStatus?: 'idle' | 'checking-allowance' | 'approving' | 'purchasing' | 'success' | 'error';
669
+ purchaseError?: string | null;
666
670
  };
667
- declare function PropertyBuy({ propertyName, propertyLocation: propertyLocationLabel, isAuthenticated, onSignIn, saleData, }: PropertyBuyProps): react_jsx_runtime.JSX.Element;
671
+ declare function PropertyBuy({ propertyName, propertyLocation: propertyLocationLabel, isAuthenticated, onSignIn, saleData, walletUsdcBalance, onPurchase, purchaseStatus, purchaseError, }: PropertyBuyProps): react_jsx_runtime.JSX.Element;
668
672
 
669
673
  type OwnerBookingProps = {
670
674
  propertyName?: string | null;
package/dist/index.js CHANGED
@@ -9910,10 +9910,14 @@ function PropertyBuy({
9910
9910
  propertyLocation: propertyLocationLabel = "Mosman, Sydney",
9911
9911
  isAuthenticated,
9912
9912
  onSignIn,
9913
- saleData
9913
+ saleData,
9914
+ walletUsdcBalance,
9915
+ onPurchase,
9916
+ purchaseStatus = "idle",
9917
+ purchaseError
9914
9918
  }) {
9915
9919
  const [sliderValue, setSliderValue] = React5.useState(0);
9916
- const [availableBalance, setAvailableBalance] = React5.useState(125e3);
9920
+ const [availableBalance, setAvailableBalance] = React5.useState(walletUsdcBalance ?? 125e3);
9917
9921
  const [userSubscription, setUserSubscription] = React5.useState(null);
9918
9922
  const [manualOrderAmount, setManualOrderAmount] = React5.useState(null);
9919
9923
  const [ownedTokens, setOwnedTokens] = React5.useState(0);
@@ -9949,6 +9953,11 @@ function PropertyBuy({
9949
9953
  const orderTotal = totalSpend;
9950
9954
  const estExposure = (tokenQuantity / supplyToSell * 100).toFixed(4);
9951
9955
  const hasInsufficientFunds = orderTotal > availableBalance;
9956
+ React5.useEffect(() => {
9957
+ if (walletUsdcBalance != null) {
9958
+ setAvailableBalance(walletUsdcBalance);
9959
+ }
9960
+ }, [walletUsdcBalance]);
9952
9961
  const handleOrderButtonClick = () => {
9953
9962
  if (!isAuthenticated) {
9954
9963
  onSignIn();
@@ -9959,8 +9968,12 @@ function PropertyBuy({
9959
9968
  }
9960
9969
  setShowOrderConfirmModal(true);
9961
9970
  };
9971
+ const isPurchaseInFlight = purchaseStatus === "checking-allowance" || purchaseStatus === "approving" || purchaseStatus === "purchasing";
9962
9972
  const getOrderButtonText = () => {
9963
9973
  if (!isAuthenticated) return "Sign In to Invest";
9974
+ if (purchaseStatus === "checking-allowance") return "Checking allowance\u2026";
9975
+ if (purchaseStatus === "approving") return "Approving USDC\u2026";
9976
+ if (purchaseStatus === "purchasing") return "Confirming purchase\u2026";
9964
9977
  if (scStatus === 0) return "Sale Not Open Yet";
9965
9978
  if (scStatus === 2) return "Sale Completed";
9966
9979
  if (scStatus === 3) return "Sale Paused";
@@ -9969,30 +9982,42 @@ function PropertyBuy({
9969
9982
  };
9970
9983
  const isOrderButtonDisabled = () => {
9971
9984
  if (!isAuthenticated) return false;
9985
+ if (isPurchaseInFlight) return true;
9972
9986
  if (scStatus !== 1) return true;
9973
9987
  if (tokenQuantity === 0) return true;
9974
9988
  return false;
9975
9989
  };
9976
- const confirmOrder = () => {
9990
+ const confirmOrder = async () => {
9977
9991
  setShowOrderConfirmModal(false);
9978
- setAvailableBalance((prev) => prev - orderTotal);
9979
- const newTokens = ownedTokens + tokenQuantity;
9992
+ const tokenAmountInt = Math.floor(tokenQuantity);
9993
+ if (tokenAmountInt <= 0) return;
9994
+ if (onPurchase) {
9995
+ try {
9996
+ await onPurchase(tokenAmountInt);
9997
+ } catch {
9998
+ return;
9999
+ }
10000
+ }
10001
+ if (walletUsdcBalance == null) {
10002
+ setAvailableBalance((prev) => prev - orderTotal);
10003
+ }
10004
+ const newTokens = ownedTokens + tokenAmountInt;
9980
10005
  setOwnedTokens(newTokens);
9981
10006
  setDisplayedOwnedTokens(newTokens);
9982
10007
  setOwnedTokensJustUpdated(true);
9983
- setLastOrderQuantity(tokenQuantity);
10008
+ setLastOrderQuantity(tokenAmountInt);
9984
10009
  setTimeout(() => setOwnedTokensJustUpdated(false), 2e3);
9985
10010
  setUserSubscription({
9986
10011
  propertyName,
9987
10012
  tokenSymbol: "MUS",
9988
- tokens: tokenQuantity,
10013
+ tokens: tokenAmountInt,
9989
10014
  value: orderTotal,
9990
10015
  avgPrice: tokenPrice,
9991
10016
  percentOfProperty: estExposure,
9992
10017
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
9993
10018
  });
9994
10019
  setLastOrderDetails({
9995
- tokens: tokenQuantity,
10020
+ tokens: tokenAmountInt,
9996
10021
  total: orderTotal,
9997
10022
  price: tokenPrice,
9998
10023
  orderNumber: Math.floor(1e7 + Math.random() * 9e7)