@bze/bze-ui-kit 1.0.13 → 1.0.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.d.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +142 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1081,18 +1081,19 @@ declare const useSigningClient: ({ chainName }: UseSigningClientProps) => {
|
|
|
1081
1081
|
|
|
1082
1082
|
/**
|
|
1083
1083
|
* Validates the wallet connection on mount and proactively disconnects if the
|
|
1084
|
-
* wallet state restored from localStorage is stale (
|
|
1085
|
-
*
|
|
1084
|
+
* wallet state restored from localStorage is stale (extension locked, or account
|
|
1085
|
+
* switched outside the UI between sessions).
|
|
1086
1086
|
*
|
|
1087
1087
|
* interchain-kit persists WalletState.Connected + the account address in
|
|
1088
|
-
* localStorage and restores it on every page load without verifying the
|
|
1089
|
-
* extension
|
|
1090
|
-
*
|
|
1091
|
-
* the
|
|
1092
|
-
* before the user tries a transaction.
|
|
1088
|
+
* localStorage and restores it on every page load without re-verifying the
|
|
1089
|
+
* extension. This hook catches that by calling refreshAccount() — interchain-kit's
|
|
1090
|
+
* own method for forcing a live fetch from the extension — and comparing the result
|
|
1091
|
+
* against the cached address. On mismatch or failure, shows a toast and disconnects.
|
|
1093
1092
|
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1093
|
+
* Runs on every status change (not just mount) because interchain-kit restores state
|
|
1094
|
+
* asynchronously, so status is Disconnected on the first render and only becomes
|
|
1095
|
+
* Connected after its own useEffect/init() completes. The hasValidated ref ensures
|
|
1096
|
+
* we only run the check once per page load.
|
|
1096
1097
|
*/
|
|
1097
1098
|
declare const useWalletHealthCheck: (chainName?: string) => void;
|
|
1098
1099
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1081,18 +1081,19 @@ declare const useSigningClient: ({ chainName }: UseSigningClientProps) => {
|
|
|
1081
1081
|
|
|
1082
1082
|
/**
|
|
1083
1083
|
* Validates the wallet connection on mount and proactively disconnects if the
|
|
1084
|
-
* wallet state restored from localStorage is stale (
|
|
1085
|
-
*
|
|
1084
|
+
* wallet state restored from localStorage is stale (extension locked, or account
|
|
1085
|
+
* switched outside the UI between sessions).
|
|
1086
1086
|
*
|
|
1087
1087
|
* interchain-kit persists WalletState.Connected + the account address in
|
|
1088
|
-
* localStorage and restores it on every page load without verifying the
|
|
1089
|
-
* extension
|
|
1090
|
-
*
|
|
1091
|
-
* the
|
|
1092
|
-
* before the user tries a transaction.
|
|
1088
|
+
* localStorage and restores it on every page load without re-verifying the
|
|
1089
|
+
* extension. This hook catches that by calling refreshAccount() — interchain-kit's
|
|
1090
|
+
* own method for forcing a live fetch from the extension — and comparing the result
|
|
1091
|
+
* against the cached address. On mismatch or failure, shows a toast and disconnects.
|
|
1093
1092
|
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1093
|
+
* Runs on every status change (not just mount) because interchain-kit restores state
|
|
1094
|
+
* asynchronously, so status is Disconnected on the first render and only becomes
|
|
1095
|
+
* Connected after its own useEffect/init() completes. The hasValidated ref ensures
|
|
1096
|
+
* we only run the check once per page load.
|
|
1096
1097
|
*/
|
|
1097
1098
|
declare const useWalletHealthCheck: (chainName?: string) => void;
|
|
1098
1099
|
|
package/dist/index.js
CHANGED
|
@@ -3652,40 +3652,95 @@ var useSigningClient = ({ chainName }) => {
|
|
|
3652
3652
|
};
|
|
3653
3653
|
|
|
3654
3654
|
// src/hooks/useWalletHealthCheck.ts
|
|
3655
|
-
var
|
|
3656
|
-
var
|
|
3655
|
+
var import_react6 = require("react");
|
|
3656
|
+
var import_react7 = require("@interchain-kit/react");
|
|
3657
3657
|
var import_core = require("@interchain-kit/core");
|
|
3658
|
+
|
|
3659
|
+
// src/components/toaster.tsx
|
|
3660
|
+
var import_react5 = require("@chakra-ui/react");
|
|
3661
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3662
|
+
var toaster = (0, import_react5.createToaster)({
|
|
3663
|
+
placement: "top-end",
|
|
3664
|
+
pauseOnPageIdle: true
|
|
3665
|
+
});
|
|
3666
|
+
var Toaster = () => {
|
|
3667
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toaster, { toaster, insetInline: { mdDown: "4" }, children: (toast) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react5.Toast.Root, { width: { md: "sm" }, children: [
|
|
3668
|
+
toast.type === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Spinner, { size: "sm", color: "blue.solid" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toast.Indicator, {}),
|
|
3669
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react5.Stack, { gap: "1", flex: "1", maxWidth: "100%", children: [
|
|
3670
|
+
toast.title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toast.Title, { children: toast.title }),
|
|
3671
|
+
toast.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toast.Description, { children: toast.description })
|
|
3672
|
+
] }),
|
|
3673
|
+
toast.action && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toast.ActionTrigger, { children: toast.action.label }),
|
|
3674
|
+
toast.closable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react5.Toast.CloseTrigger, {})
|
|
3675
|
+
] }) }) });
|
|
3676
|
+
};
|
|
3677
|
+
|
|
3678
|
+
// src/hooks/useWalletHealthCheck.ts
|
|
3658
3679
|
var SIGNING_CLIENT_TIMEOUT_MS = 5e3;
|
|
3659
3680
|
var useWalletHealthCheck = (chainName) => {
|
|
3660
|
-
const { status,
|
|
3661
|
-
(0,
|
|
3681
|
+
const { status, disconnect, address, wallet } = (0, import_react7.useChain)(chainName != null ? chainName : getChainName());
|
|
3682
|
+
const hasValidated = (0, import_react6.useRef)(false);
|
|
3683
|
+
(0, import_react6.useEffect)(() => {
|
|
3662
3684
|
if (status !== import_core.WalletState.Connected) return;
|
|
3685
|
+
if (hasValidated.current) return;
|
|
3686
|
+
hasValidated.current = true;
|
|
3663
3687
|
const validate = async () => {
|
|
3688
|
+
var _a2, _b2;
|
|
3664
3689
|
try {
|
|
3665
|
-
const
|
|
3666
|
-
|
|
3690
|
+
const refreshed = await Promise.race([
|
|
3691
|
+
(_a2 = wallet == null ? void 0 : wallet.refreshAccount) == null ? void 0 : _a2.call(wallet).then(() => true),
|
|
3667
3692
|
new Promise(
|
|
3668
|
-
(resolve) => setTimeout(() => resolve(
|
|
3693
|
+
(resolve) => setTimeout(() => resolve(false), SIGNING_CLIENT_TIMEOUT_MS)
|
|
3669
3694
|
)
|
|
3670
3695
|
]);
|
|
3671
|
-
if (!
|
|
3696
|
+
if (!refreshed) {
|
|
3697
|
+
console.error("[useWalletHealthCheck] refreshAccount timed out \u2014 wallet may be locked. Disconnecting.");
|
|
3698
|
+
toaster.create({
|
|
3699
|
+
title: "Wallet disconnected",
|
|
3700
|
+
description: "Could not reach your wallet extension. Please reconnect.",
|
|
3701
|
+
type: "error",
|
|
3702
|
+
duration: 8e3,
|
|
3703
|
+
closable: true
|
|
3704
|
+
});
|
|
3672
3705
|
disconnect();
|
|
3706
|
+
return;
|
|
3673
3707
|
}
|
|
3674
|
-
|
|
3708
|
+
const freshAccount = await ((_b2 = wallet == null ? void 0 : wallet.getAccount) == null ? void 0 : _b2.call(wallet));
|
|
3709
|
+
const freshAddress = freshAccount == null ? void 0 : freshAccount.address;
|
|
3710
|
+
if (freshAddress && freshAddress !== address) {
|
|
3711
|
+
console.error(`[useWalletHealthCheck] Address mismatch \u2014 interchain-kit cached "${address}" but extension reports "${freshAddress}". Wallet was switched outside the UI. Disconnecting.`);
|
|
3712
|
+
toaster.create({
|
|
3713
|
+
title: "Wallet account changed",
|
|
3714
|
+
description: "Your wallet account changed since your last visit. Please reconnect.",
|
|
3715
|
+
type: "warning",
|
|
3716
|
+
duration: 8e3,
|
|
3717
|
+
closable: true
|
|
3718
|
+
});
|
|
3719
|
+
disconnect();
|
|
3720
|
+
}
|
|
3721
|
+
} catch (err) {
|
|
3722
|
+
console.error("[useWalletHealthCheck] Error validating wallet connection:", err);
|
|
3723
|
+
toaster.create({
|
|
3724
|
+
title: "Wallet connection error",
|
|
3725
|
+
description: "Could not verify your wallet connection. Please reconnect.",
|
|
3726
|
+
type: "error",
|
|
3727
|
+
duration: 8e3,
|
|
3728
|
+
closable: true
|
|
3729
|
+
});
|
|
3675
3730
|
disconnect();
|
|
3676
3731
|
}
|
|
3677
3732
|
};
|
|
3678
3733
|
validate();
|
|
3679
|
-
}, []);
|
|
3734
|
+
}, [status]);
|
|
3680
3735
|
};
|
|
3681
3736
|
|
|
3682
3737
|
// src/hooks/usePrices.ts
|
|
3683
|
-
var
|
|
3738
|
+
var import_react8 = require("react");
|
|
3684
3739
|
function useAssetPrice(denom) {
|
|
3685
3740
|
const { usdPricesMap, marketsDataMap, isLoadingPrices } = useAssetsContext();
|
|
3686
|
-
const usdDenom = (0,
|
|
3687
|
-
const bzeDenom = (0,
|
|
3688
|
-
const change = (0,
|
|
3741
|
+
const usdDenom = (0, import_react8.useMemo)(() => getUSDCDenom(), []);
|
|
3742
|
+
const bzeDenom = (0, import_react8.useMemo)(() => getChainNativeAssetDenom(), []);
|
|
3743
|
+
const change = (0, import_react8.useMemo)(() => {
|
|
3689
3744
|
const marketData = marketsDataMap.get(createMarketId(denom, usdDenom));
|
|
3690
3745
|
if (marketData) {
|
|
3691
3746
|
return marketData.change;
|
|
@@ -3696,20 +3751,20 @@ function useAssetPrice(denom) {
|
|
|
3696
3751
|
}
|
|
3697
3752
|
return 0;
|
|
3698
3753
|
}, [marketsDataMap, denom, usdDenom, bzeDenom]);
|
|
3699
|
-
const price = (0,
|
|
3754
|
+
const price = (0, import_react8.useMemo)(() => {
|
|
3700
3755
|
const zeroBN = toBigNumber(0);
|
|
3701
3756
|
if (denom === "") return zeroBN;
|
|
3702
3757
|
if (denom === usdDenom) return toBigNumber(1);
|
|
3703
3758
|
return usdPricesMap.get(denom) || zeroBN;
|
|
3704
3759
|
}, [usdPricesMap, denom, usdDenom]);
|
|
3705
|
-
const totalUsdValue = (0,
|
|
3760
|
+
const totalUsdValue = (0, import_react8.useCallback)((amount) => {
|
|
3706
3761
|
return price.multipliedBy(amount);
|
|
3707
3762
|
}, [price]);
|
|
3708
|
-
const uAmountUsdValue = (0,
|
|
3763
|
+
const uAmountUsdValue = (0, import_react8.useCallback)((amount, decimals) => {
|
|
3709
3764
|
return totalUsdValue(uAmountToBigNumberAmount(amount, decimals));
|
|
3710
3765
|
}, [totalUsdValue]);
|
|
3711
|
-
const isUSDC = (0,
|
|
3712
|
-
const hasPrice = (0,
|
|
3766
|
+
const isUSDC = (0, import_react8.useMemo)(() => denom === usdDenom, [denom, usdDenom]);
|
|
3767
|
+
const hasPrice = (0, import_react8.useMemo)(() => price.gt(0), [price]);
|
|
3713
3768
|
return {
|
|
3714
3769
|
price,
|
|
3715
3770
|
change,
|
|
@@ -3722,36 +3777,36 @@ function useAssetPrice(denom) {
|
|
|
3722
3777
|
}
|
|
3723
3778
|
|
|
3724
3779
|
// src/hooks/useSettings.ts
|
|
3725
|
-
var
|
|
3780
|
+
var import_react9 = require("react");
|
|
3726
3781
|
function useSettings() {
|
|
3727
|
-
const [settings, setSettingsState] = (0,
|
|
3728
|
-
const [isLoaded, setIsLoaded] = (0,
|
|
3729
|
-
(0,
|
|
3782
|
+
const [settings, setSettingsState] = (0, import_react9.useState)(DEFAULT_SETTINGS);
|
|
3783
|
+
const [isLoaded, setIsLoaded] = (0, import_react9.useState)(false);
|
|
3784
|
+
(0, import_react9.useEffect)(() => {
|
|
3730
3785
|
setSettingsState(getSettings());
|
|
3731
3786
|
setIsLoaded(true);
|
|
3732
3787
|
}, []);
|
|
3733
|
-
const saveSettings = (0,
|
|
3788
|
+
const saveSettings = (0, import_react9.useCallback)((newSettings) => {
|
|
3734
3789
|
setSettings(newSettings);
|
|
3735
3790
|
setSettingsState(newSettings);
|
|
3736
3791
|
return true;
|
|
3737
3792
|
}, []);
|
|
3738
|
-
const updateEndpoints = (0,
|
|
3793
|
+
const updateEndpoints = (0, import_react9.useCallback)((endpoints) => {
|
|
3739
3794
|
const newSettings = __spreadProps(__spreadValues({}, settings), { endpoints });
|
|
3740
3795
|
return saveSettings(newSettings);
|
|
3741
3796
|
}, [settings, saveSettings]);
|
|
3742
|
-
const updatePreferredFeeDenom = (0,
|
|
3797
|
+
const updatePreferredFeeDenom = (0, import_react9.useCallback)((preferredFeeDenom) => {
|
|
3743
3798
|
const newSettings = __spreadProps(__spreadValues({}, settings), { preferredFeeDenom });
|
|
3744
3799
|
return saveSettings(newSettings);
|
|
3745
3800
|
}, [settings, saveSettings]);
|
|
3746
|
-
const resetToDefaults = (0,
|
|
3801
|
+
const resetToDefaults = (0, import_react9.useCallback)(() => {
|
|
3747
3802
|
saveSettings(DEFAULT_SETTINGS);
|
|
3748
3803
|
return true;
|
|
3749
3804
|
}, [saveSettings]);
|
|
3750
|
-
const getEndpoints = (0,
|
|
3805
|
+
const getEndpoints = (0, import_react9.useCallback)(() => {
|
|
3751
3806
|
return settings.endpoints;
|
|
3752
3807
|
}, [settings.endpoints]);
|
|
3753
|
-
const defaultSettings = (0,
|
|
3754
|
-
const feeDenom = (0,
|
|
3808
|
+
const defaultSettings = (0, import_react9.useMemo)(() => DEFAULT_SETTINGS, []);
|
|
3809
|
+
const feeDenom = (0, import_react9.useMemo)(() => settings.preferredFeeDenom || getChainNativeAssetDenom(), [settings.preferredFeeDenom]);
|
|
3755
3810
|
return {
|
|
3756
3811
|
settings,
|
|
3757
3812
|
isLoaded,
|
|
@@ -3767,14 +3822,14 @@ function useSettings() {
|
|
|
3767
3822
|
|
|
3768
3823
|
// src/hooks/useBalances.ts
|
|
3769
3824
|
var import_bignumber8 = __toESM(require("bignumber.js"));
|
|
3770
|
-
var
|
|
3825
|
+
var import_react10 = require("react");
|
|
3771
3826
|
function useBalances() {
|
|
3772
3827
|
const { balancesMap, isLoading, assetsMap, usdPricesMap } = useAssetsContext();
|
|
3773
|
-
const balances = (0,
|
|
3774
|
-
const getBalanceByDenom = (0,
|
|
3828
|
+
const balances = (0, import_react10.useMemo)(() => Array.from(balancesMap.values()), [balancesMap]);
|
|
3829
|
+
const getBalanceByDenom = (0, import_react10.useCallback)((denom) => {
|
|
3775
3830
|
return balancesMap.get(denom) || { denom, amount: (0, import_bignumber8.default)(0) };
|
|
3776
3831
|
}, [balancesMap]);
|
|
3777
|
-
const assetsBalances = (0,
|
|
3832
|
+
const assetsBalances = (0, import_react10.useMemo)(() => {
|
|
3778
3833
|
const result = [];
|
|
3779
3834
|
balances.map((bal) => {
|
|
3780
3835
|
const asset = assetsMap.get(bal.denom);
|
|
@@ -3804,14 +3859,14 @@ function useBalances() {
|
|
|
3804
3859
|
}
|
|
3805
3860
|
function useBalance(denom) {
|
|
3806
3861
|
const { balancesMap, isLoading } = useAssetsContext();
|
|
3807
|
-
const balance = (0,
|
|
3862
|
+
const balance = (0, import_react10.useMemo)(
|
|
3808
3863
|
() => balancesMap.get(denom) || {
|
|
3809
3864
|
denom,
|
|
3810
3865
|
amount: (0, import_bignumber8.default)(0)
|
|
3811
3866
|
},
|
|
3812
3867
|
[balancesMap, denom]
|
|
3813
3868
|
);
|
|
3814
|
-
const hasAmount = (0,
|
|
3869
|
+
const hasAmount = (0, import_react10.useCallback)((amount) => {
|
|
3815
3870
|
return balance.amount.gte(amount);
|
|
3816
3871
|
}, [balance]);
|
|
3817
3872
|
return {
|
|
@@ -3822,7 +3877,7 @@ function useBalance(denom) {
|
|
|
3822
3877
|
}
|
|
3823
3878
|
|
|
3824
3879
|
// src/hooks/useEpochs.ts
|
|
3825
|
-
var
|
|
3880
|
+
var import_react11 = require("react");
|
|
3826
3881
|
var import_bignumber9 = __toESM(require("bignumber.js"));
|
|
3827
3882
|
var EPOCH_HOUR2 = "hour";
|
|
3828
3883
|
var EPOCH_DAY2 = "day";
|
|
@@ -3842,28 +3897,28 @@ function getEpochDurationByIdentifier2(identifier) {
|
|
|
3842
3897
|
}
|
|
3843
3898
|
function useEpochs() {
|
|
3844
3899
|
const { epochs, isLoading, updateEpochs } = useAssetsContext();
|
|
3845
|
-
const getCurrentEpoch2 = (0,
|
|
3900
|
+
const getCurrentEpoch2 = (0, import_react11.useCallback)((identifier) => {
|
|
3846
3901
|
return epochs.get(identifier);
|
|
3847
3902
|
}, [epochs]);
|
|
3848
|
-
const hourEpochInfo = (0,
|
|
3903
|
+
const hourEpochInfo = (0, import_react11.useMemo)(() => {
|
|
3849
3904
|
return epochs.get(EPOCH_HOUR2);
|
|
3850
3905
|
}, [epochs]);
|
|
3851
|
-
const dayEpochInfo = (0,
|
|
3906
|
+
const dayEpochInfo = (0, import_react11.useMemo)(() => {
|
|
3852
3907
|
return epochs.get(EPOCH_DAY2);
|
|
3853
3908
|
}, [epochs]);
|
|
3854
|
-
const weekEpochInfo = (0,
|
|
3909
|
+
const weekEpochInfo = (0, import_react11.useMemo)(() => {
|
|
3855
3910
|
return epochs.get(EPOCH_WEEK2);
|
|
3856
3911
|
}, [epochs]);
|
|
3857
|
-
const getHourEpochInfo2 = (0,
|
|
3912
|
+
const getHourEpochInfo2 = (0, import_react11.useCallback)(() => {
|
|
3858
3913
|
return epochs.get(EPOCH_HOUR2);
|
|
3859
3914
|
}, [epochs]);
|
|
3860
|
-
const getDayEpochInfo = (0,
|
|
3915
|
+
const getDayEpochInfo = (0, import_react11.useCallback)(() => {
|
|
3861
3916
|
return epochs.get(EPOCH_DAY2);
|
|
3862
3917
|
}, [epochs]);
|
|
3863
|
-
const getWeekEpochInfo2 = (0,
|
|
3918
|
+
const getWeekEpochInfo2 = (0, import_react11.useCallback)(() => {
|
|
3864
3919
|
return epochs.get(EPOCH_WEEK2);
|
|
3865
3920
|
}, [epochs]);
|
|
3866
|
-
const getPeriodicEpochEndTime2 = (0,
|
|
3921
|
+
const getPeriodicEpochEndTime2 = (0, import_react11.useCallback)((identifier, modWeek = 1) => {
|
|
3867
3922
|
const epoch = epochs.get(identifier);
|
|
3868
3923
|
if (!epoch || !epoch.current_epoch_start_time) {
|
|
3869
3924
|
return void 0;
|
|
@@ -3878,13 +3933,13 @@ function useEpochs() {
|
|
|
3878
3933
|
startAt.setTime(startAt.getTime() + duration + duration * remainingEpochs);
|
|
3879
3934
|
return startAt;
|
|
3880
3935
|
}, [epochs]);
|
|
3881
|
-
const getCurrentWeekEpochEndTime2 = (0,
|
|
3936
|
+
const getCurrentWeekEpochEndTime2 = (0, import_react11.useCallback)(() => {
|
|
3882
3937
|
return getPeriodicEpochEndTime2(EPOCH_WEEK2);
|
|
3883
3938
|
}, [getPeriodicEpochEndTime2]);
|
|
3884
|
-
const getPeriodicWeekEpochEndTime2 = (0,
|
|
3939
|
+
const getPeriodicWeekEpochEndTime2 = (0, import_react11.useCallback)((modWeek = 1) => {
|
|
3885
3940
|
return getPeriodicEpochEndTime2(EPOCH_WEEK2, modWeek);
|
|
3886
3941
|
}, [getPeriodicEpochEndTime2]);
|
|
3887
|
-
const epochsList = (0,
|
|
3942
|
+
const epochsList = (0, import_react11.useMemo)(() => Array.from(epochs.values()), [epochs]);
|
|
3888
3943
|
return {
|
|
3889
3944
|
epochs: epochsList,
|
|
3890
3945
|
epochsMap: epochs,
|
|
@@ -3911,22 +3966,22 @@ function useEpochsManager() {
|
|
|
3911
3966
|
}
|
|
3912
3967
|
|
|
3913
3968
|
// src/hooks/useLiquidityPools.ts
|
|
3914
|
-
var
|
|
3969
|
+
var import_react12 = require("react");
|
|
3915
3970
|
var import_bignumber10 = __toESM(require("bignumber.js"));
|
|
3916
3971
|
function useLiquidityPools() {
|
|
3917
3972
|
const { poolsMap, poolsDataMap, updateLiquidityPools, isLoading, assetsMap } = useAssetsContext();
|
|
3918
|
-
const pools = (0,
|
|
3973
|
+
const pools = (0, import_react12.useMemo)(() => {
|
|
3919
3974
|
return Array.from(poolsMap.values());
|
|
3920
3975
|
}, [poolsMap]);
|
|
3921
3976
|
const getPoolByLpDenom = (lpDenom) => {
|
|
3922
3977
|
const poolId = poolIdFromPoolDenom(lpDenom);
|
|
3923
3978
|
return poolsMap.get(poolId);
|
|
3924
3979
|
};
|
|
3925
|
-
const getDenomsPool = (0,
|
|
3980
|
+
const getDenomsPool = (0, import_react12.useCallback)((denomA, denomB) => {
|
|
3926
3981
|
const poolId = createPoolId(denomA, denomB);
|
|
3927
3982
|
return poolsMap.get(poolId);
|
|
3928
3983
|
}, [poolsMap]);
|
|
3929
|
-
const liquidAssets = (0,
|
|
3984
|
+
const liquidAssets = (0, import_react12.useMemo)(() => {
|
|
3930
3985
|
if (!assetsMap || assetsMap.size === 0) return [];
|
|
3931
3986
|
const result = /* @__PURE__ */ new Map();
|
|
3932
3987
|
pools.forEach((pool) => {
|
|
@@ -3949,12 +4004,12 @@ function useLiquidityPools() {
|
|
|
3949
4004
|
}
|
|
3950
4005
|
function useAssetLiquidityPools(denom) {
|
|
3951
4006
|
const { poolsMap, poolsDataMap, isLoading } = useAssetsContext();
|
|
3952
|
-
const assetPools = (0,
|
|
4007
|
+
const assetPools = (0, import_react12.useMemo)(() => {
|
|
3953
4008
|
return Array.from(poolsMap.values()).filter(
|
|
3954
4009
|
(pool) => pool.base === denom || pool.quote === denom
|
|
3955
4010
|
);
|
|
3956
4011
|
}, [poolsMap, denom]);
|
|
3957
|
-
const assetPoolsData = (0,
|
|
4012
|
+
const assetPoolsData = (0, import_react12.useMemo)(() => {
|
|
3958
4013
|
const newMap = /* @__PURE__ */ new Map();
|
|
3959
4014
|
if (isLoading || denom === "") return newMap;
|
|
3960
4015
|
assetPools.forEach((pool) => {
|
|
@@ -3965,7 +4020,7 @@ function useAssetLiquidityPools(denom) {
|
|
|
3965
4020
|
});
|
|
3966
4021
|
return newMap;
|
|
3967
4022
|
}, [assetPools, poolsDataMap, isLoading, denom]);
|
|
3968
|
-
const asset24HoursVolume = (0,
|
|
4023
|
+
const asset24HoursVolume = (0, import_react12.useMemo)(() => {
|
|
3969
4024
|
let volume = (0, import_bignumber10.default)(0);
|
|
3970
4025
|
if (isLoading || denom === "") return volume;
|
|
3971
4026
|
assetPoolsData.forEach((poolData) => {
|
|
@@ -3987,47 +4042,47 @@ function useAssetLiquidityPools(denom) {
|
|
|
3987
4042
|
}
|
|
3988
4043
|
function useLiquidityPool(poolId) {
|
|
3989
4044
|
const { balancesMap, assetsMap, poolsMap, poolsDataMap, isLoading } = useAssetsContext();
|
|
3990
|
-
const pool = (0,
|
|
3991
|
-
const poolData = (0,
|
|
3992
|
-
const userShares = (0,
|
|
4045
|
+
const pool = (0, import_react12.useMemo)(() => poolsMap.get(poolId), [poolsMap, poolId]);
|
|
4046
|
+
const poolData = (0, import_react12.useMemo)(() => poolsDataMap.get(poolId), [poolsDataMap, poolId]);
|
|
4047
|
+
const userShares = (0, import_react12.useMemo)(() => {
|
|
3993
4048
|
if (!pool) return toBigNumber(0);
|
|
3994
4049
|
const balance = balancesMap.get(pool.lp_denom);
|
|
3995
4050
|
if (!balance) return toBigNumber(0);
|
|
3996
4051
|
return toBigNumber(balance.amount);
|
|
3997
4052
|
}, [balancesMap, pool]);
|
|
3998
|
-
const totalShares = (0,
|
|
4053
|
+
const totalShares = (0, import_react12.useMemo)(() => {
|
|
3999
4054
|
if (!assetsMap || !pool) return toBigNumber(0);
|
|
4000
4055
|
const sharesAsset = assetsMap.get(pool.lp_denom);
|
|
4001
4056
|
if (!sharesAsset) return toBigNumber(0);
|
|
4002
4057
|
return toBigNumber((sharesAsset == null ? void 0 : sharesAsset.supply) || 0);
|
|
4003
4058
|
}, [assetsMap, pool]);
|
|
4004
|
-
const userSharesPercentage = (0,
|
|
4059
|
+
const userSharesPercentage = (0, import_react12.useMemo)(() => {
|
|
4005
4060
|
if (!userShares || !totalShares || totalShares.isZero()) {
|
|
4006
4061
|
return toBigNumber(0);
|
|
4007
4062
|
}
|
|
4008
4063
|
return userShares.dividedBy(totalShares).multipliedBy(100).toFixed(2);
|
|
4009
4064
|
}, [userShares, totalShares]);
|
|
4010
|
-
const userReserveBase = (0,
|
|
4065
|
+
const userReserveBase = (0, import_react12.useMemo)(() => {
|
|
4011
4066
|
if (!pool || !userShares || !totalShares || totalShares.isZero()) {
|
|
4012
4067
|
return toBigNumber(0);
|
|
4013
4068
|
}
|
|
4014
4069
|
const reserveBase = toBigNumber(pool.reserve_base);
|
|
4015
4070
|
return userShares.dividedBy(totalShares).multipliedBy(reserveBase);
|
|
4016
4071
|
}, [pool, userShares, totalShares]);
|
|
4017
|
-
const userReserveQuote = (0,
|
|
4072
|
+
const userReserveQuote = (0, import_react12.useMemo)(() => {
|
|
4018
4073
|
if (!pool || !userShares || !totalShares || totalShares.isZero()) {
|
|
4019
4074
|
return toBigNumber(0);
|
|
4020
4075
|
}
|
|
4021
4076
|
const reserveQuote = toBigNumber(pool.reserve_quote);
|
|
4022
4077
|
return userShares.dividedBy(totalShares).multipliedBy(reserveQuote);
|
|
4023
4078
|
}, [pool, userShares, totalShares]);
|
|
4024
|
-
const calculateOppositeAmount = (0,
|
|
4079
|
+
const calculateOppositeAmount = (0, import_react12.useCallback)((amount, isBase) => {
|
|
4025
4080
|
if (!pool) {
|
|
4026
4081
|
return toBigNumber(0);
|
|
4027
4082
|
}
|
|
4028
4083
|
return calculatePoolOppositeAmount(pool, amount, isBase);
|
|
4029
4084
|
}, [pool]);
|
|
4030
|
-
const calculateSharesFromAmounts = (0,
|
|
4085
|
+
const calculateSharesFromAmounts = (0, import_react12.useCallback)((baseAmount, quoteAmount) => {
|
|
4031
4086
|
if (!pool || !totalShares) {
|
|
4032
4087
|
return toBigNumber(0);
|
|
4033
4088
|
}
|
|
@@ -4062,11 +4117,11 @@ function useLiquidityPool(poolId) {
|
|
|
4062
4117
|
}
|
|
4063
4118
|
|
|
4064
4119
|
// src/hooks/useAssetsValue.ts
|
|
4065
|
-
var
|
|
4120
|
+
var import_react13 = require("react");
|
|
4066
4121
|
var import_bignumber11 = __toESM(require("bignumber.js"));
|
|
4067
4122
|
function useAssetsValue() {
|
|
4068
4123
|
const { assetsMap, usdPricesMap, balancesMap, isLoading: isLoadingPrices } = useAssetsContext();
|
|
4069
|
-
const totalUsdValue = (0,
|
|
4124
|
+
const totalUsdValue = (0, import_react13.useCallback)((prettyBalances) => {
|
|
4070
4125
|
let usdValue = (0, import_bignumber11.default)(0);
|
|
4071
4126
|
prettyBalances.map((denomBalance) => {
|
|
4072
4127
|
const assetPrice = usdPricesMap.get(denomBalance.denom);
|
|
@@ -4076,7 +4131,7 @@ function useAssetsValue() {
|
|
|
4076
4131
|
});
|
|
4077
4132
|
return usdValue;
|
|
4078
4133
|
}, [usdPricesMap]);
|
|
4079
|
-
const walletTotalUsdValue = (0,
|
|
4134
|
+
const walletTotalUsdValue = (0, import_react13.useMemo)(() => {
|
|
4080
4135
|
let total = toBigNumber(0);
|
|
4081
4136
|
balancesMap.forEach((balance, denom) => {
|
|
4082
4137
|
const price = usdPricesMap.get(denom);
|
|
@@ -4087,14 +4142,14 @@ function useAssetsValue() {
|
|
|
4087
4142
|
});
|
|
4088
4143
|
return total;
|
|
4089
4144
|
}, [balancesMap, usdPricesMap, assetsMap]);
|
|
4090
|
-
const denomUsdValue = (0,
|
|
4145
|
+
const denomUsdValue = (0, import_react13.useCallback)((denom, uAmount) => {
|
|
4091
4146
|
const price = usdPricesMap.get(denom);
|
|
4092
4147
|
if (!price || !price.gt(0)) return toBigNumber(0);
|
|
4093
4148
|
const asset = assetsMap.get(denom);
|
|
4094
4149
|
if (!asset) return toBigNumber(0);
|
|
4095
4150
|
return price.multipliedBy(uAmountToBigNumberAmount(uAmount, asset.decimals));
|
|
4096
4151
|
}, [usdPricesMap, assetsMap]);
|
|
4097
|
-
const compareValues = (0,
|
|
4152
|
+
const compareValues = (0, import_react13.useCallback)((a, b) => {
|
|
4098
4153
|
var _a2;
|
|
4099
4154
|
let aValue = (0, import_bignumber11.default)(0);
|
|
4100
4155
|
const aPrice = usdPricesMap.get(a.denom);
|
|
@@ -4118,13 +4173,13 @@ function useAssetsValue() {
|
|
|
4118
4173
|
}
|
|
4119
4174
|
|
|
4120
4175
|
// src/hooks/useFeeTokens.ts
|
|
4121
|
-
var
|
|
4176
|
+
var import_react14 = require("react");
|
|
4122
4177
|
var MIN_LIQUIDITY_FOR_FEE_TOKEN = 5e10;
|
|
4123
4178
|
function useFeeTokens() {
|
|
4124
4179
|
const { pools, isLoading: poolsLoading } = useLiquidityPools();
|
|
4125
4180
|
const { assetsMap, isLoading: assetsLoading } = useAssetsContext();
|
|
4126
4181
|
const nativeDenom = getChainNativeAssetDenom();
|
|
4127
|
-
const feeTokens = (0,
|
|
4182
|
+
const feeTokens = (0, import_react14.useMemo)(() => {
|
|
4128
4183
|
if (poolsLoading || assetsLoading) {
|
|
4129
4184
|
return [];
|
|
4130
4185
|
}
|
|
@@ -4154,17 +4209,17 @@ function useFeeTokens() {
|
|
|
4154
4209
|
}
|
|
4155
4210
|
|
|
4156
4211
|
// src/hooks/useMarkets.ts
|
|
4157
|
-
var
|
|
4212
|
+
var import_react15 = require("react");
|
|
4158
4213
|
var import_bignumber12 = __toESM(require("bignumber.js"));
|
|
4159
4214
|
function useMarkets() {
|
|
4160
4215
|
const { marketsMap, marketsDataMap, updateMarkets, isLoading } = useAssetsContext();
|
|
4161
|
-
const markets = (0,
|
|
4216
|
+
const markets = (0, import_react15.useMemo)(() => {
|
|
4162
4217
|
return Array.from(marketsMap.values());
|
|
4163
4218
|
}, [marketsMap]);
|
|
4164
|
-
const marketsData = (0,
|
|
4165
|
-
const marketExists = (0,
|
|
4166
|
-
const getMarketData = (0,
|
|
4167
|
-
const getMarket = (0,
|
|
4219
|
+
const marketsData = (0, import_react15.useMemo)(() => Array.from(marketsDataMap.values()), [marketsDataMap]);
|
|
4220
|
+
const marketExists = (0, import_react15.useCallback)((marketId) => marketsMap.has(marketId), [marketsMap]);
|
|
4221
|
+
const getMarketData = (0, import_react15.useCallback)((marketId) => marketsDataMap.get(marketId), [marketsDataMap]);
|
|
4222
|
+
const getMarket = (0, import_react15.useCallback)((marketId) => marketsMap.get(marketId), [marketsMap]);
|
|
4168
4223
|
return {
|
|
4169
4224
|
markets,
|
|
4170
4225
|
marketsData,
|
|
@@ -4179,9 +4234,9 @@ function useMarkets() {
|
|
|
4179
4234
|
}
|
|
4180
4235
|
function useAssetMarkets(denom) {
|
|
4181
4236
|
const { isLoading, marketsMap, marketsDataMap } = useAssetsContext();
|
|
4182
|
-
const markets = (0,
|
|
4183
|
-
const marketsData = (0,
|
|
4184
|
-
const assetMarkets = (0,
|
|
4237
|
+
const markets = (0, import_react15.useMemo)(() => Array.from(marketsMap.values()), [marketsMap]);
|
|
4238
|
+
const marketsData = (0, import_react15.useMemo)(() => Array.from(marketsDataMap.values()), [marketsDataMap]);
|
|
4239
|
+
const assetMarkets = (0, import_react15.useMemo)(() => {
|
|
4185
4240
|
const baseMatches = [];
|
|
4186
4241
|
const quoteMatches = [];
|
|
4187
4242
|
for (const market of markets) {
|
|
@@ -4190,7 +4245,7 @@ function useAssetMarkets(denom) {
|
|
|
4190
4245
|
}
|
|
4191
4246
|
return [...baseMatches, ...quoteMatches];
|
|
4192
4247
|
}, [markets, denom]);
|
|
4193
|
-
const assetMarketsData = (0,
|
|
4248
|
+
const assetMarketsData = (0, import_react15.useMemo)(() => {
|
|
4194
4249
|
const baseMatches = [];
|
|
4195
4250
|
const quoteMatches = [];
|
|
4196
4251
|
for (const market of marketsData) {
|
|
@@ -4199,7 +4254,7 @@ function useAssetMarkets(denom) {
|
|
|
4199
4254
|
}
|
|
4200
4255
|
return [...baseMatches, ...quoteMatches];
|
|
4201
4256
|
}, [marketsData, denom]);
|
|
4202
|
-
const asset24hTradedVolume = (0,
|
|
4257
|
+
const asset24hTradedVolume = (0, import_react15.useMemo)(() => {
|
|
4203
4258
|
return assetMarketsData.reduce((acc, market) => {
|
|
4204
4259
|
if (denom === market.base) {
|
|
4205
4260
|
return acc.plus(market.base_volume || 0);
|
|
@@ -4218,8 +4273,8 @@ function useAssetMarkets(denom) {
|
|
|
4218
4273
|
}
|
|
4219
4274
|
function useMarket(marketId) {
|
|
4220
4275
|
const { marketsMap, marketsDataMap, isLoading, assetsMap } = useAssetsContext();
|
|
4221
|
-
const market = (0,
|
|
4222
|
-
const marketSymbol = (0,
|
|
4276
|
+
const market = (0, import_react15.useMemo)(() => marketsMap.get(marketId), [marketsMap, marketId]);
|
|
4277
|
+
const marketSymbol = (0, import_react15.useMemo)(() => {
|
|
4223
4278
|
var _a2, _b2;
|
|
4224
4279
|
if (isLoading) return "";
|
|
4225
4280
|
if (!market) return "";
|
|
@@ -4233,9 +4288,9 @@ function useMarket(marketId) {
|
|
|
4233
4288
|
}
|
|
4234
4289
|
return `${base}/${quote}`;
|
|
4235
4290
|
}, [market, isLoading, assetsMap]);
|
|
4236
|
-
const marketData = (0,
|
|
4237
|
-
const marketExists = (0,
|
|
4238
|
-
const volume24h = (0,
|
|
4291
|
+
const marketData = (0, import_react15.useMemo)(() => marketsDataMap.get(marketId), [marketsDataMap, marketId]);
|
|
4292
|
+
const marketExists = (0, import_react15.useMemo)(() => !!market, [market]);
|
|
4293
|
+
const volume24h = (0, import_react15.useMemo)(() => {
|
|
4239
4294
|
if (!marketData || !market) return toBigNumber(0);
|
|
4240
4295
|
const quoteAsset = assetsMap.get(market.quote);
|
|
4241
4296
|
if (!quoteAsset) return toBigNumber(0);
|
|
@@ -4261,27 +4316,6 @@ function useMarketsManager() {
|
|
|
4261
4316
|
|
|
4262
4317
|
// src/hooks/useToast.tsx
|
|
4263
4318
|
var import_react16 = require("react");
|
|
4264
|
-
|
|
4265
|
-
// src/components/toaster.tsx
|
|
4266
|
-
var import_react15 = require("@chakra-ui/react");
|
|
4267
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
4268
|
-
var toaster = (0, import_react15.createToaster)({
|
|
4269
|
-
placement: "top-end",
|
|
4270
|
-
pauseOnPageIdle: true
|
|
4271
|
-
});
|
|
4272
|
-
var Toaster = () => {
|
|
4273
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toaster, { toaster, insetInline: { mdDown: "4" }, children: (toast) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react15.Toast.Root, { width: { md: "sm" }, children: [
|
|
4274
|
-
toast.type === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Spinner, { size: "sm", color: "blue.solid" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toast.Indicator, {}),
|
|
4275
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react15.Stack, { gap: "1", flex: "1", maxWidth: "100%", children: [
|
|
4276
|
-
toast.title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toast.Title, { children: toast.title }),
|
|
4277
|
-
toast.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toast.Description, { children: toast.description })
|
|
4278
|
-
] }),
|
|
4279
|
-
toast.action && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toast.ActionTrigger, { children: toast.action.label }),
|
|
4280
|
-
toast.closable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react15.Toast.CloseTrigger, {})
|
|
4281
|
-
] }) }) });
|
|
4282
|
-
};
|
|
4283
|
-
|
|
4284
|
-
// src/hooks/useToast.tsx
|
|
4285
4319
|
var useToast = () => {
|
|
4286
4320
|
const clickableSuccess = (0, import_react16.useCallback)((title, actionFn, actionLabel, description, duration = 5e3) => {
|
|
4287
4321
|
toaster.create({
|