@cofhe/react 0.0.0-alpha-20260601105140 → 0.0.0-alpha-20260602122344
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/{chunk-AFU2LVEH.js → chunk-DSFIX7QP.js} +267 -269
- package/dist/{chunk-AFU2LVEH.js.map → chunk-DSFIX7QP.js.map} +1 -1
- package/dist/{chunk-GWNGM2KD.cjs → chunk-SNIXBOED.cjs} +292 -294
- package/dist/chunk-SNIXBOED.cjs.map +1 -0
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -3
- package/dist/index.d.ts +51 -3
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/ui-base.cjs +2 -2
- package/dist/ui-base.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-GWNGM2KD.cjs.map +0 -1
|
@@ -2754,6 +2754,138 @@ function useCofheWriteContract(options) {
|
|
|
2754
2754
|
};
|
|
2755
2755
|
}
|
|
2756
2756
|
|
|
2757
|
+
// src/hooks/useTransactionGlobalLifecycle.ts
|
|
2758
|
+
import { ContractFunctionExecutionError as ContractFunctionExecutionError2, ContractFunctionRevertedError as ContractFunctionRevertedError2 } from "viem";
|
|
2759
|
+
var TOAST_DELAY_MS = 1e4;
|
|
2760
|
+
function useTransactionGlobalToastsLifecycle() {
|
|
2761
|
+
const { addToast } = usePortalToasts();
|
|
2762
|
+
return {
|
|
2763
|
+
// 1.tx is submitted
|
|
2764
|
+
onTransactionSubmitted: (transaction) => {
|
|
2765
|
+
cofheLogger.log("____ Transaction submitted:", transaction);
|
|
2766
|
+
addToast(
|
|
2767
|
+
{
|
|
2768
|
+
variant: "info",
|
|
2769
|
+
title: `${transaction.actionType} Transaction Submitted`,
|
|
2770
|
+
description: `${transaction.actionType} transaction has been submitted.`,
|
|
2771
|
+
transaction: {
|
|
2772
|
+
hash: transaction.hash,
|
|
2773
|
+
chainId: transaction.chainId
|
|
2774
|
+
}
|
|
2775
|
+
},
|
|
2776
|
+
TOAST_DELAY_MS
|
|
2777
|
+
);
|
|
2778
|
+
},
|
|
2779
|
+
onTransactionSubmitError: (error, transactionType) => {
|
|
2780
|
+
let humanReadableError;
|
|
2781
|
+
if (error instanceof ContractFunctionExecutionError2) {
|
|
2782
|
+
if (error.cause instanceof ContractFunctionRevertedError2) {
|
|
2783
|
+
const reasonOfRevert = error.cause.raw;
|
|
2784
|
+
if (typeof reasonOfRevert === "string") {
|
|
2785
|
+
humanReadableError = cofheHumanizeRevertReason(reasonOfRevert);
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
cofheLogger.error("____ Transaction submission failed for type:", transactionType, "with error:", error);
|
|
2790
|
+
addToast(
|
|
2791
|
+
{
|
|
2792
|
+
variant: "error",
|
|
2793
|
+
title: `${transactionType} Transaction Submission Failed`,
|
|
2794
|
+
description: humanReadableError ?? (error instanceof Error ? error.message : "An unknown error occurred during transaction submission.")
|
|
2795
|
+
},
|
|
2796
|
+
TOAST_DELAY_MS
|
|
2797
|
+
);
|
|
2798
|
+
},
|
|
2799
|
+
// 2.a. tx is mined (could be success or fail)
|
|
2800
|
+
onTransactionMined: (transaction, receipt) => {
|
|
2801
|
+
cofheLogger.log("____ Transaction mined:", transaction, "with receipt:", receipt);
|
|
2802
|
+
if (receipt.status === "success") {
|
|
2803
|
+
addToast(
|
|
2804
|
+
{
|
|
2805
|
+
variant: "success",
|
|
2806
|
+
title: `${transaction.actionType} Transaction Mined`,
|
|
2807
|
+
description: `${transaction.actionType} transaction has been mined.`,
|
|
2808
|
+
transaction: {
|
|
2809
|
+
hash: transaction.hash,
|
|
2810
|
+
chainId: transaction.chainId
|
|
2811
|
+
}
|
|
2812
|
+
},
|
|
2813
|
+
TOAST_DELAY_MS
|
|
2814
|
+
);
|
|
2815
|
+
} else {
|
|
2816
|
+
addToast(
|
|
2817
|
+
{
|
|
2818
|
+
variant: "error",
|
|
2819
|
+
title: `${transaction.actionType} Transaction Failed`,
|
|
2820
|
+
description: `${transaction.actionType} transaction has failed.`,
|
|
2821
|
+
transaction: {
|
|
2822
|
+
hash: transaction.hash,
|
|
2823
|
+
chainId: transaction.chainId
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
TOAST_DELAY_MS
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
},
|
|
2830
|
+
// 2.b. tx receipt fetch failed
|
|
2831
|
+
onWatchReceiptFailure: (error, transaction) => {
|
|
2832
|
+
cofheLogger.error("____ Transaction receipt fetch failed for tx:", transaction, "with error:", error);
|
|
2833
|
+
addToast(
|
|
2834
|
+
{
|
|
2835
|
+
variant: "error",
|
|
2836
|
+
title: `${transaction.actionType} Transaction Fetch Failed`,
|
|
2837
|
+
description: `Fetching ${transaction.actionType} transaction has failed.`,
|
|
2838
|
+
transaction: {
|
|
2839
|
+
hash: transaction.hash,
|
|
2840
|
+
chainId: transaction.chainId
|
|
2841
|
+
}
|
|
2842
|
+
},
|
|
2843
|
+
TOAST_DELAY_MS
|
|
2844
|
+
);
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
}
|
|
2848
|
+
function useTransactionGlobalLifecycle() {
|
|
2849
|
+
const {
|
|
2850
|
+
onTransactionSubmitted: handleToastsOnTransactionSubmitted,
|
|
2851
|
+
onTransactionMined: handleToastsOnTransactionMined,
|
|
2852
|
+
onWatchReceiptFailure: handleToastsOnWatchReceiptFailure,
|
|
2853
|
+
onTransactionSubmitError: handleToastsOnTransactionSubmitError
|
|
2854
|
+
} = useTransactionGlobalToastsLifecycle();
|
|
2855
|
+
return {
|
|
2856
|
+
onTransactionSubmitted: handleToastsOnTransactionSubmitted,
|
|
2857
|
+
onTransactionMined: handleToastsOnTransactionMined,
|
|
2858
|
+
onWatchReceiptFailure: handleToastsOnWatchReceiptFailure,
|
|
2859
|
+
onTransactionSubmitError: handleToastsOnTransactionSubmitError
|
|
2860
|
+
};
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
// src/hooks/useCofheTokenApprove.ts
|
|
2864
|
+
function useCofheTokenApprove(writeMutationOptions) {
|
|
2865
|
+
const { onSuccess: passedOnSuccess, onError: passedOnError, ...restOfOptions } = writeMutationOptions || {};
|
|
2866
|
+
const { onTransactionSubmitError } = useTransactionGlobalLifecycle();
|
|
2867
|
+
return useCofheWriteContract({
|
|
2868
|
+
...restOfOptions,
|
|
2869
|
+
onError: (error, variables, onMutateResult, context) => {
|
|
2870
|
+
if (passedOnError) passedOnError(error, variables, onMutateResult, context);
|
|
2871
|
+
onTransactionSubmitError(error, "approve" /* Approve */);
|
|
2872
|
+
},
|
|
2873
|
+
onSuccess: (hash, variables, onMutateResult, context) => {
|
|
2874
|
+
if (passedOnSuccess) passedOnSuccess(hash, variables, onMutateResult, context);
|
|
2875
|
+
if (!hasExtras(variables)) return;
|
|
2876
|
+
const { token, tokenAmount, account } = variables.extras;
|
|
2877
|
+
useTransactionStore.getState().addTransaction({
|
|
2878
|
+
hash,
|
|
2879
|
+
token,
|
|
2880
|
+
tokenAmount,
|
|
2881
|
+
chainId: token.chainId,
|
|
2882
|
+
actionType: "approve" /* Approve */,
|
|
2883
|
+
account
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2757
2889
|
// src/hooks/useCofheTokenLists.ts
|
|
2758
2890
|
import "@tanstack/react-query";
|
|
2759
2891
|
import { useMemo as useMemo9 } from "react";
|
|
@@ -3661,114 +3793,6 @@ function useCofheTokenClaimable({ accountAddress: account, token }, queryOptions
|
|
|
3661
3793
|
var import_ts_essentials7 = __toESM(require_dist(), 1);
|
|
3662
3794
|
import "@tanstack/react-query";
|
|
3663
3795
|
import "viem";
|
|
3664
|
-
|
|
3665
|
-
// src/hooks/useTransactionGlobalLifecycle.ts
|
|
3666
|
-
import { ContractFunctionExecutionError as ContractFunctionExecutionError2, ContractFunctionRevertedError as ContractFunctionRevertedError2 } from "viem";
|
|
3667
|
-
var TOAST_DELAY_MS = 1e4;
|
|
3668
|
-
function useTransactionGlobalToastsLifecycle() {
|
|
3669
|
-
const { addToast } = usePortalToasts();
|
|
3670
|
-
return {
|
|
3671
|
-
// 1.tx is submitted
|
|
3672
|
-
onTransactionSubmitted: (transaction) => {
|
|
3673
|
-
cofheLogger.log("____ Transaction submitted:", transaction);
|
|
3674
|
-
addToast(
|
|
3675
|
-
{
|
|
3676
|
-
variant: "info",
|
|
3677
|
-
title: `${transaction.actionType} Transaction Submitted`,
|
|
3678
|
-
description: `${transaction.actionType} transaction has been submitted.`,
|
|
3679
|
-
transaction: {
|
|
3680
|
-
hash: transaction.hash,
|
|
3681
|
-
chainId: transaction.chainId
|
|
3682
|
-
}
|
|
3683
|
-
},
|
|
3684
|
-
TOAST_DELAY_MS
|
|
3685
|
-
);
|
|
3686
|
-
},
|
|
3687
|
-
onTransactionSubmitError: (error, transactionType) => {
|
|
3688
|
-
let humanReadableError;
|
|
3689
|
-
if (error instanceof ContractFunctionExecutionError2) {
|
|
3690
|
-
if (error.cause instanceof ContractFunctionRevertedError2) {
|
|
3691
|
-
const reasonOfRevert = error.cause.raw;
|
|
3692
|
-
if (typeof reasonOfRevert === "string") {
|
|
3693
|
-
humanReadableError = cofheHumanizeRevertReason(reasonOfRevert);
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
cofheLogger.error("____ Transaction submission failed for type:", transactionType, "with error:", error);
|
|
3698
|
-
addToast(
|
|
3699
|
-
{
|
|
3700
|
-
variant: "error",
|
|
3701
|
-
title: `${transactionType} Transaction Submission Failed`,
|
|
3702
|
-
description: humanReadableError ?? (error instanceof Error ? error.message : "An unknown error occurred during transaction submission.")
|
|
3703
|
-
},
|
|
3704
|
-
TOAST_DELAY_MS
|
|
3705
|
-
);
|
|
3706
|
-
},
|
|
3707
|
-
// 2.a. tx is mined (could be success or fail)
|
|
3708
|
-
onTransactionMined: (transaction, receipt) => {
|
|
3709
|
-
cofheLogger.log("____ Transaction mined:", transaction, "with receipt:", receipt);
|
|
3710
|
-
if (receipt.status === "success") {
|
|
3711
|
-
addToast(
|
|
3712
|
-
{
|
|
3713
|
-
variant: "success",
|
|
3714
|
-
title: `${transaction.actionType} Transaction Mined`,
|
|
3715
|
-
description: `${transaction.actionType} transaction has been mined.`,
|
|
3716
|
-
transaction: {
|
|
3717
|
-
hash: transaction.hash,
|
|
3718
|
-
chainId: transaction.chainId
|
|
3719
|
-
}
|
|
3720
|
-
},
|
|
3721
|
-
TOAST_DELAY_MS
|
|
3722
|
-
);
|
|
3723
|
-
} else {
|
|
3724
|
-
addToast(
|
|
3725
|
-
{
|
|
3726
|
-
variant: "error",
|
|
3727
|
-
title: `${transaction.actionType} Transaction Failed`,
|
|
3728
|
-
description: `${transaction.actionType} transaction has failed.`,
|
|
3729
|
-
transaction: {
|
|
3730
|
-
hash: transaction.hash,
|
|
3731
|
-
chainId: transaction.chainId
|
|
3732
|
-
}
|
|
3733
|
-
},
|
|
3734
|
-
TOAST_DELAY_MS
|
|
3735
|
-
);
|
|
3736
|
-
}
|
|
3737
|
-
},
|
|
3738
|
-
// 2.b. tx receipt fetch failed
|
|
3739
|
-
onWatchReceiptFailure: (error, transaction) => {
|
|
3740
|
-
cofheLogger.error("____ Transaction receipt fetch failed for tx:", transaction, "with error:", error);
|
|
3741
|
-
addToast(
|
|
3742
|
-
{
|
|
3743
|
-
variant: "error",
|
|
3744
|
-
title: `${transaction.actionType} Transaction Fetch Failed`,
|
|
3745
|
-
description: `Fetching ${transaction.actionType} transaction has failed.`,
|
|
3746
|
-
transaction: {
|
|
3747
|
-
hash: transaction.hash,
|
|
3748
|
-
chainId: transaction.chainId
|
|
3749
|
-
}
|
|
3750
|
-
},
|
|
3751
|
-
TOAST_DELAY_MS
|
|
3752
|
-
);
|
|
3753
|
-
}
|
|
3754
|
-
};
|
|
3755
|
-
}
|
|
3756
|
-
function useTransactionGlobalLifecycle() {
|
|
3757
|
-
const {
|
|
3758
|
-
onTransactionSubmitted: handleToastsOnTransactionSubmitted,
|
|
3759
|
-
onTransactionMined: handleToastsOnTransactionMined,
|
|
3760
|
-
onWatchReceiptFailure: handleToastsOnWatchReceiptFailure,
|
|
3761
|
-
onTransactionSubmitError: handleToastsOnTransactionSubmitError
|
|
3762
|
-
} = useTransactionGlobalToastsLifecycle();
|
|
3763
|
-
return {
|
|
3764
|
-
onTransactionSubmitted: handleToastsOnTransactionSubmitted,
|
|
3765
|
-
onTransactionMined: handleToastsOnTransactionMined,
|
|
3766
|
-
onWatchReceiptFailure: handleToastsOnWatchReceiptFailure,
|
|
3767
|
-
onTransactionSubmitError: handleToastsOnTransactionSubmitError
|
|
3768
|
-
};
|
|
3769
|
-
}
|
|
3770
|
-
|
|
3771
|
-
// src/hooks/useCofheTokenClaimUnshielded.ts
|
|
3772
3796
|
function getCofheTokenClaimUnshieldedCallArgs(params) {
|
|
3773
3797
|
const { token, account, claim, claims } = params;
|
|
3774
3798
|
const tokenAddress = token.address;
|
|
@@ -4089,8 +4113,123 @@ function useCofheTokenDecryptedBalance({ token, accountAddress, displayDecimals
|
|
|
4089
4113
|
};
|
|
4090
4114
|
}
|
|
4091
4115
|
|
|
4116
|
+
// src/hooks/useCofheTokenPublicBalance.ts
|
|
4117
|
+
var import_ts_essentials10 = __toESM(require_dist(), 1);
|
|
4118
|
+
import "@tanstack/react-query";
|
|
4119
|
+
import "viem";
|
|
4120
|
+
function constructPublicTokenBalanceQueryKey({
|
|
4121
|
+
chainId,
|
|
4122
|
+
accountAddress,
|
|
4123
|
+
tokenAddress
|
|
4124
|
+
}) {
|
|
4125
|
+
return ["tokenBalance", chainId, accountAddress?.toLowerCase(), tokenAddress?.toLowerCase()];
|
|
4126
|
+
}
|
|
4127
|
+
function constructPublicTokenBalanceQueryKeyForInvalidation({
|
|
4128
|
+
chainId,
|
|
4129
|
+
accountAddress,
|
|
4130
|
+
tokenAddress
|
|
4131
|
+
}) {
|
|
4132
|
+
return constructPublicTokenBalanceQueryKey({
|
|
4133
|
+
chainId,
|
|
4134
|
+
accountAddress,
|
|
4135
|
+
tokenAddress
|
|
4136
|
+
});
|
|
4137
|
+
}
|
|
4138
|
+
function getPublicTokenBalanceSource(token) {
|
|
4139
|
+
const confidentialityType = token?.extensions.fhenix.confidentialityType;
|
|
4140
|
+
const underlyingErc20 = token?.extensions.fhenix.erc20Pair;
|
|
4141
|
+
const publicBalanceSourceType = getPublicBalanceSourceType(confidentialityType);
|
|
4142
|
+
const tokenToFetchBalanceFrom = publicBalanceSourceType === "erc20Pair" ? underlyingErc20 : publicBalanceSourceType === "token" ? token : void 0;
|
|
4143
|
+
if (!tokenToFetchBalanceFrom) return void 0;
|
|
4144
|
+
return {
|
|
4145
|
+
address: tokenToFetchBalanceFrom.address,
|
|
4146
|
+
decimals: tokenToFetchBalanceFrom.decimals
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
function createPublicTokenBalanceQueryOptions(params) {
|
|
4150
|
+
const { publicClient, accountAddress, tokenAddress, queryOptions } = params;
|
|
4151
|
+
const { enabled: userEnabled, ...restQueryOptions } = queryOptions ?? {};
|
|
4152
|
+
const baseEnabled = !!publicClient && !!accountAddress && !!tokenAddress;
|
|
4153
|
+
const enabled = baseEnabled && (userEnabled ?? true);
|
|
4154
|
+
const queryKey = constructPublicTokenBalanceQueryKey({
|
|
4155
|
+
chainId: publicClient?.chain?.id,
|
|
4156
|
+
accountAddress,
|
|
4157
|
+
tokenAddress
|
|
4158
|
+
});
|
|
4159
|
+
return {
|
|
4160
|
+
queryKey,
|
|
4161
|
+
queryFn: withInvalidationContext(
|
|
4162
|
+
async ({ invalidationContext, signal }) => {
|
|
4163
|
+
(0, import_ts_essentials10.assert)(tokenAddress, "Token address is required to fetch token balance");
|
|
4164
|
+
(0, import_ts_essentials10.assert)(publicClient, "PublicClient is required to fetch token balance");
|
|
4165
|
+
(0, import_ts_essentials10.assert)(accountAddress, "Account address is required to fetch token balance");
|
|
4166
|
+
const isNativeToken = tokenAddress.toLowerCase() === ETH_ADDRESS_LOWERCASE;
|
|
4167
|
+
const balance = await maybeWaitUntilRpcAware(
|
|
4168
|
+
publicClient,
|
|
4169
|
+
{
|
|
4170
|
+
blockHashToBeAwareOf: invalidationContext?.blockHashToBeAwareOf,
|
|
4171
|
+
readDescription: isNativeToken ? "read native balance" : "read ERC20 balance",
|
|
4172
|
+
read: () => isNativeToken ? publicClient.getBalance({
|
|
4173
|
+
address: accountAddress
|
|
4174
|
+
}) : publicClient.readContract({
|
|
4175
|
+
address: tokenAddress,
|
|
4176
|
+
abi: ERC20_BALANCE_OF_ABI,
|
|
4177
|
+
functionName: "balanceOf",
|
|
4178
|
+
args: [accountAddress]
|
|
4179
|
+
})
|
|
4180
|
+
},
|
|
4181
|
+
{ signal }
|
|
4182
|
+
);
|
|
4183
|
+
return balance;
|
|
4184
|
+
}
|
|
4185
|
+
),
|
|
4186
|
+
enabled,
|
|
4187
|
+
refetchOnMount: false,
|
|
4188
|
+
...restQueryOptions
|
|
4189
|
+
};
|
|
4190
|
+
}
|
|
4191
|
+
function useTokenBalance({ tokenAddress, accountAddress }, queryOptions) {
|
|
4192
|
+
const publicClient = useCofhePublicClient();
|
|
4193
|
+
return useInternalQuery(
|
|
4194
|
+
createPublicTokenBalanceQueryOptions({
|
|
4195
|
+
publicClient,
|
|
4196
|
+
accountAddress,
|
|
4197
|
+
tokenAddress,
|
|
4198
|
+
queryOptions
|
|
4199
|
+
})
|
|
4200
|
+
);
|
|
4201
|
+
}
|
|
4202
|
+
function useCofheTokenPublicBalance({ token, accountAddress, displayDecimals = 5 }, options) {
|
|
4203
|
+
const connectedAccount = useCofheAccount();
|
|
4204
|
+
const account = accountAddress || connectedAccount;
|
|
4205
|
+
const { enabled: userEnabled = true, ...restOptions } = options ?? {};
|
|
4206
|
+
const tokenToFetchBalanceFrom = getPublicTokenBalanceSource(token);
|
|
4207
|
+
const { data, isFetching, refetch } = useTokenBalance(
|
|
4208
|
+
{
|
|
4209
|
+
tokenAddress: tokenToFetchBalanceFrom?.address,
|
|
4210
|
+
accountAddress: account
|
|
4211
|
+
},
|
|
4212
|
+
{
|
|
4213
|
+
enabled: userEnabled,
|
|
4214
|
+
select: (value) => {
|
|
4215
|
+
(0, import_ts_essentials10.assert)(
|
|
4216
|
+
typeof tokenToFetchBalanceFrom?.decimals === "number",
|
|
4217
|
+
"Token decimals must be defined to format public token balance"
|
|
4218
|
+
);
|
|
4219
|
+
return formatTokenAmount(value, tokenToFetchBalanceFrom.decimals, displayDecimals);
|
|
4220
|
+
},
|
|
4221
|
+
...restOptions
|
|
4222
|
+
}
|
|
4223
|
+
);
|
|
4224
|
+
return {
|
|
4225
|
+
data,
|
|
4226
|
+
isFetching,
|
|
4227
|
+
refetch
|
|
4228
|
+
};
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4092
4231
|
// src/hooks/useCofheTokensClaimable.ts
|
|
4093
|
-
var
|
|
4232
|
+
var import_ts_essentials12 = __toESM(require_dist(), 1);
|
|
4094
4233
|
import "@tanstack/react-query";
|
|
4095
4234
|
import "react";
|
|
4096
4235
|
import "viem";
|
|
@@ -4122,7 +4261,7 @@ function useNormalizedList(items, options) {
|
|
|
4122
4261
|
}
|
|
4123
4262
|
|
|
4124
4263
|
// src/hooks/useStoredTransactions.ts
|
|
4125
|
-
var
|
|
4264
|
+
var import_ts_essentials11 = __toESM(require_dist());
|
|
4126
4265
|
import { useMemo as useMemo11 } from "react";
|
|
4127
4266
|
function useStoredTransactions({
|
|
4128
4267
|
chainId,
|
|
@@ -4155,7 +4294,7 @@ function useStoredTransactions({
|
|
|
4155
4294
|
return reducer?.(filtered);
|
|
4156
4295
|
}, [filtered, reducer]);
|
|
4157
4296
|
const uniqueHashes = new Set(filtered.map((tx) => tx.hash));
|
|
4158
|
-
(0,
|
|
4297
|
+
(0, import_ts_essentials11.assert)(
|
|
4159
4298
|
uniqueHashes.size === filtered.length,
|
|
4160
4299
|
"There should be no duplicate transactions with the same hash in the result"
|
|
4161
4300
|
);
|
|
@@ -4230,12 +4369,12 @@ function useCofheTokensClaimable({ tokens, accountAddress: account }, queryOptio
|
|
|
4230
4369
|
return {
|
|
4231
4370
|
queryKey,
|
|
4232
4371
|
queryFn: withInvalidationContext(async ({ signal, invalidationContext }) => {
|
|
4233
|
-
(0,
|
|
4372
|
+
(0, import_ts_essentials12.assert)(
|
|
4234
4373
|
isTokenConfidentialityTypeClaimable(confidentialityType),
|
|
4235
4374
|
"confidentialityType narrowed by token guard"
|
|
4236
4375
|
);
|
|
4237
|
-
(0,
|
|
4238
|
-
(0,
|
|
4376
|
+
(0, import_ts_essentials12.assert)(account, "account is required to fetch unshield claims");
|
|
4377
|
+
(0, import_ts_essentials12.assert)(publicClient, "publicClient is required to fetch unshield claims");
|
|
4239
4378
|
return fetchUnshieldClaimsSummary({
|
|
4240
4379
|
publicClient,
|
|
4241
4380
|
token,
|
|
@@ -4298,7 +4437,7 @@ function useCofheTokensClaimable({ tokens, accountAddress: account }, queryOptio
|
|
|
4298
4437
|
// src/hooks/useCofheTokenShield.ts
|
|
4299
4438
|
import "@tanstack/react-query";
|
|
4300
4439
|
import "viem";
|
|
4301
|
-
var
|
|
4440
|
+
var import_ts_essentials13 = __toESM(require_dist(), 1);
|
|
4302
4441
|
function getCofheTokenShieldCallArgs(params) {
|
|
4303
4442
|
const { token, amount, account } = params;
|
|
4304
4443
|
const tokenAddress = token.address;
|
|
@@ -4408,8 +4547,8 @@ function useCofheTokenShield(options) {
|
|
|
4408
4547
|
onTransactionSubmitError(error, "shield" /* Shield */);
|
|
4409
4548
|
},
|
|
4410
4549
|
onSuccess: async (hash, input, onMutateResult, context) => {
|
|
4411
|
-
(0,
|
|
4412
|
-
(0,
|
|
4550
|
+
(0, import_ts_essentials13.assert)(chainId, "Chain ID is required for token shield");
|
|
4551
|
+
(0, import_ts_essentials13.assert)(account, "Wallet account is required for token shield");
|
|
4413
4552
|
if (onSuccess) await onSuccess(hash, input, onMutateResult, context);
|
|
4414
4553
|
useTransactionStore.getState().addTransaction({
|
|
4415
4554
|
hash,
|
|
@@ -4428,7 +4567,7 @@ function useCofheTokenShield(options) {
|
|
|
4428
4567
|
import { useMemo as useMemo13 } from "react";
|
|
4429
4568
|
|
|
4430
4569
|
// src/hooks/useCofheReadContracts.ts
|
|
4431
|
-
var
|
|
4570
|
+
var import_ts_essentials14 = __toESM(require_dist(), 1);
|
|
4432
4571
|
import "@tanstack/react-query";
|
|
4433
4572
|
import { transformEncryptedReturnTypes as transformEncryptedReturnTypes2 } from "@cofhe/abi";
|
|
4434
4573
|
var QUERY_CACHE_PREFIX3 = "cofheReadContracts";
|
|
@@ -4473,8 +4612,8 @@ function useCofheReadContracts(params, queryOptions) {
|
|
|
4473
4612
|
allowFailure: multicallOptions?.allowFailure
|
|
4474
4613
|
}),
|
|
4475
4614
|
queryFn: async () => {
|
|
4476
|
-
(0,
|
|
4477
|
-
(0,
|
|
4615
|
+
(0, import_ts_essentials14.assert)(publicClient, "PublicClient should be guaranteed by enabled check");
|
|
4616
|
+
(0, import_ts_essentials14.assert)(contracts && contracts.length > 0, "Contracts should be guaranteed by enabled check");
|
|
4478
4617
|
const raw = await publicClient.multicall({
|
|
4479
4618
|
contracts,
|
|
4480
4619
|
...multicallOptions || {}
|
|
@@ -4702,17 +4841,17 @@ function useCofheTokenTransfer(writeMutationOptions) {
|
|
|
4702
4841
|
// src/hooks/useCofheTokenUnshield.ts
|
|
4703
4842
|
import "@tanstack/react-query";
|
|
4704
4843
|
import "viem";
|
|
4705
|
-
var
|
|
4844
|
+
var import_ts_essentials16 = __toESM(require_dist(), 1);
|
|
4706
4845
|
|
|
4707
4846
|
// src/hooks/useStoredTransaction.ts
|
|
4708
4847
|
import { useMemo as useMemo14 } from "react";
|
|
4709
|
-
var
|
|
4848
|
+
var import_ts_essentials15 = __toESM(require_dist(), 1);
|
|
4710
4849
|
function useStoredTransaction(txHash) {
|
|
4711
4850
|
const filter2 = useMemo14(() => {
|
|
4712
4851
|
return (tx) => tx.hash === txHash;
|
|
4713
4852
|
}, [txHash]);
|
|
4714
4853
|
const { filteredTxs } = useStoredTransactions({ filter: filter2 });
|
|
4715
|
-
(0,
|
|
4854
|
+
(0, import_ts_essentials15.assert)(filteredTxs.length <= 1, "There should be at most one transaction with a given hash");
|
|
4716
4855
|
return filteredTxs[0];
|
|
4717
4856
|
}
|
|
4718
4857
|
|
|
@@ -4817,8 +4956,8 @@ function useCofheTokenUnshieldMutation(options) {
|
|
|
4817
4956
|
onTransactionSubmitError(error, "unshield" /* Unshield */);
|
|
4818
4957
|
},
|
|
4819
4958
|
onSuccess: async (hash, input, onMutateResult, context) => {
|
|
4820
|
-
(0,
|
|
4821
|
-
(0,
|
|
4959
|
+
(0, import_ts_essentials16.assert)(chainId, "Chain ID is required for token unshield");
|
|
4960
|
+
(0, import_ts_essentials16.assert)(account, "Wallet account is required for token unshield");
|
|
4822
4961
|
if (onSuccess) await onSuccess(hash, input, onMutateResult, context);
|
|
4823
4962
|
useTransactionStore.getState().addTransaction({
|
|
4824
4963
|
hash,
|
|
@@ -4985,123 +5124,6 @@ function useCoingeckoUsdPrice({
|
|
|
4985
5124
|
|
|
4986
5125
|
// src/hooks/useTokensWithPublicBalances.ts
|
|
4987
5126
|
import { useMemo as useMemo15 } from "react";
|
|
4988
|
-
|
|
4989
|
-
// src/hooks/useCofheTokenPublicBalance.ts
|
|
4990
|
-
var import_ts_essentials16 = __toESM(require_dist(), 1);
|
|
4991
|
-
import "@tanstack/react-query";
|
|
4992
|
-
import "viem";
|
|
4993
|
-
function constructPublicTokenBalanceQueryKey({
|
|
4994
|
-
chainId,
|
|
4995
|
-
accountAddress,
|
|
4996
|
-
tokenAddress
|
|
4997
|
-
}) {
|
|
4998
|
-
return ["tokenBalance", chainId, accountAddress?.toLowerCase(), tokenAddress?.toLowerCase()];
|
|
4999
|
-
}
|
|
5000
|
-
function constructPublicTokenBalanceQueryKeyForInvalidation({
|
|
5001
|
-
chainId,
|
|
5002
|
-
accountAddress,
|
|
5003
|
-
tokenAddress
|
|
5004
|
-
}) {
|
|
5005
|
-
return constructPublicTokenBalanceQueryKey({
|
|
5006
|
-
chainId,
|
|
5007
|
-
accountAddress,
|
|
5008
|
-
tokenAddress
|
|
5009
|
-
});
|
|
5010
|
-
}
|
|
5011
|
-
function getPublicTokenBalanceSource(token) {
|
|
5012
|
-
const confidentialityType = token?.extensions.fhenix.confidentialityType;
|
|
5013
|
-
const underlyingErc20 = token?.extensions.fhenix.erc20Pair;
|
|
5014
|
-
const publicBalanceSourceType = getPublicBalanceSourceType(confidentialityType);
|
|
5015
|
-
const tokenToFetchBalanceFrom = publicBalanceSourceType === "erc20Pair" ? underlyingErc20 : publicBalanceSourceType === "token" ? token : void 0;
|
|
5016
|
-
if (!tokenToFetchBalanceFrom) return void 0;
|
|
5017
|
-
return {
|
|
5018
|
-
address: tokenToFetchBalanceFrom.address,
|
|
5019
|
-
decimals: tokenToFetchBalanceFrom.decimals
|
|
5020
|
-
};
|
|
5021
|
-
}
|
|
5022
|
-
function createPublicTokenBalanceQueryOptions(params) {
|
|
5023
|
-
const { publicClient, accountAddress, tokenAddress, queryOptions } = params;
|
|
5024
|
-
const { enabled: userEnabled, ...restQueryOptions } = queryOptions ?? {};
|
|
5025
|
-
const baseEnabled = !!publicClient && !!accountAddress && !!tokenAddress;
|
|
5026
|
-
const enabled = baseEnabled && (userEnabled ?? true);
|
|
5027
|
-
const queryKey = constructPublicTokenBalanceQueryKey({
|
|
5028
|
-
chainId: publicClient?.chain?.id,
|
|
5029
|
-
accountAddress,
|
|
5030
|
-
tokenAddress
|
|
5031
|
-
});
|
|
5032
|
-
return {
|
|
5033
|
-
queryKey,
|
|
5034
|
-
queryFn: withInvalidationContext(
|
|
5035
|
-
async ({ invalidationContext, signal }) => {
|
|
5036
|
-
(0, import_ts_essentials16.assert)(tokenAddress, "Token address is required to fetch token balance");
|
|
5037
|
-
(0, import_ts_essentials16.assert)(publicClient, "PublicClient is required to fetch token balance");
|
|
5038
|
-
(0, import_ts_essentials16.assert)(accountAddress, "Account address is required to fetch token balance");
|
|
5039
|
-
const isNativeToken = tokenAddress.toLowerCase() === ETH_ADDRESS_LOWERCASE;
|
|
5040
|
-
const balance = await maybeWaitUntilRpcAware(
|
|
5041
|
-
publicClient,
|
|
5042
|
-
{
|
|
5043
|
-
blockHashToBeAwareOf: invalidationContext?.blockHashToBeAwareOf,
|
|
5044
|
-
readDescription: isNativeToken ? "read native balance" : "read ERC20 balance",
|
|
5045
|
-
read: () => isNativeToken ? publicClient.getBalance({
|
|
5046
|
-
address: accountAddress
|
|
5047
|
-
}) : publicClient.readContract({
|
|
5048
|
-
address: tokenAddress,
|
|
5049
|
-
abi: ERC20_BALANCE_OF_ABI,
|
|
5050
|
-
functionName: "balanceOf",
|
|
5051
|
-
args: [accountAddress]
|
|
5052
|
-
})
|
|
5053
|
-
},
|
|
5054
|
-
{ signal }
|
|
5055
|
-
);
|
|
5056
|
-
return balance;
|
|
5057
|
-
}
|
|
5058
|
-
),
|
|
5059
|
-
enabled,
|
|
5060
|
-
refetchOnMount: false,
|
|
5061
|
-
...restQueryOptions
|
|
5062
|
-
};
|
|
5063
|
-
}
|
|
5064
|
-
function useTokenBalance({ tokenAddress, accountAddress }, queryOptions) {
|
|
5065
|
-
const publicClient = useCofhePublicClient();
|
|
5066
|
-
return useInternalQuery(
|
|
5067
|
-
createPublicTokenBalanceQueryOptions({
|
|
5068
|
-
publicClient,
|
|
5069
|
-
accountAddress,
|
|
5070
|
-
tokenAddress,
|
|
5071
|
-
queryOptions
|
|
5072
|
-
})
|
|
5073
|
-
);
|
|
5074
|
-
}
|
|
5075
|
-
function useCofheTokenPublicBalance({ token, accountAddress, displayDecimals = 5 }, options) {
|
|
5076
|
-
const connectedAccount = useCofheAccount();
|
|
5077
|
-
const account = accountAddress || connectedAccount;
|
|
5078
|
-
const { enabled: userEnabled = true, ...restOptions } = options ?? {};
|
|
5079
|
-
const tokenToFetchBalanceFrom = getPublicTokenBalanceSource(token);
|
|
5080
|
-
const { data, isFetching, refetch } = useTokenBalance(
|
|
5081
|
-
{
|
|
5082
|
-
tokenAddress: tokenToFetchBalanceFrom?.address,
|
|
5083
|
-
accountAddress: account
|
|
5084
|
-
},
|
|
5085
|
-
{
|
|
5086
|
-
enabled: userEnabled,
|
|
5087
|
-
select: (value) => {
|
|
5088
|
-
(0, import_ts_essentials16.assert)(
|
|
5089
|
-
typeof tokenToFetchBalanceFrom?.decimals === "number",
|
|
5090
|
-
"Token decimals must be defined to format public token balance"
|
|
5091
|
-
);
|
|
5092
|
-
return formatTokenAmount(value, tokenToFetchBalanceFrom.decimals, displayDecimals);
|
|
5093
|
-
},
|
|
5094
|
-
...restOptions
|
|
5095
|
-
}
|
|
5096
|
-
);
|
|
5097
|
-
return {
|
|
5098
|
-
data,
|
|
5099
|
-
isFetching,
|
|
5100
|
-
refetch
|
|
5101
|
-
};
|
|
5102
|
-
}
|
|
5103
|
-
|
|
5104
|
-
// src/hooks/useTokensWithPublicBalances.ts
|
|
5105
5127
|
function useTokensWithPublicBalances({ chainId: _chainId, accountAddress, displayDecimals = 5 } = {}, options) {
|
|
5106
5128
|
const connectedAccount = useCofheAccount();
|
|
5107
5129
|
const account = accountAddress ?? connectedAccount;
|
|
@@ -5778,32 +5800,6 @@ var usePermitDetailsAndActions = (permitHash) => {
|
|
|
5778
5800
|
};
|
|
5779
5801
|
};
|
|
5780
5802
|
|
|
5781
|
-
// src/hooks/useCofheTokenApprove.ts
|
|
5782
|
-
function useCofheTokenApprove(writeMutationOptions) {
|
|
5783
|
-
const { onSuccess: passedOnSuccess, onError: passedOnError, ...restOfOptions } = writeMutationOptions || {};
|
|
5784
|
-
const { onTransactionSubmitError } = useTransactionGlobalLifecycle();
|
|
5785
|
-
return useCofheWriteContract({
|
|
5786
|
-
...restOfOptions,
|
|
5787
|
-
onError: (error, variables, onMutateResult, context) => {
|
|
5788
|
-
if (passedOnError) passedOnError(error, variables, onMutateResult, context);
|
|
5789
|
-
onTransactionSubmitError(error, "approve" /* Approve */);
|
|
5790
|
-
},
|
|
5791
|
-
onSuccess: (hash, variables, onMutateResult, context) => {
|
|
5792
|
-
if (passedOnSuccess) passedOnSuccess(hash, variables, onMutateResult, context);
|
|
5793
|
-
if (!hasExtras(variables)) return;
|
|
5794
|
-
const { token, tokenAmount, account } = variables.extras;
|
|
5795
|
-
useTransactionStore.getState().addTransaction({
|
|
5796
|
-
hash,
|
|
5797
|
-
token,
|
|
5798
|
-
tokenAmount,
|
|
5799
|
-
chainId: token.chainId,
|
|
5800
|
-
actionType: "approve" /* Approve */,
|
|
5801
|
-
account
|
|
5802
|
-
});
|
|
5803
|
-
}
|
|
5804
|
-
});
|
|
5805
|
-
}
|
|
5806
|
-
|
|
5807
5803
|
// src/hooks/useReschedulableTimeout.ts
|
|
5808
5804
|
import { useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
5809
5805
|
function useReschedulableTimeout(callback, defaultTimeout) {
|
|
@@ -11179,6 +11175,7 @@ export {
|
|
|
11179
11175
|
statusToString,
|
|
11180
11176
|
useTransactionStore,
|
|
11181
11177
|
useCofheWriteContract,
|
|
11178
|
+
useCofheTokenApprove,
|
|
11182
11179
|
useCofheTokenLists,
|
|
11183
11180
|
useCofheTokens,
|
|
11184
11181
|
useCofheTokenClaimable,
|
|
@@ -11186,6 +11183,7 @@ export {
|
|
|
11186
11183
|
useCofheTokenClaimUnshielded,
|
|
11187
11184
|
useCofheReadContractAndDecrypt,
|
|
11188
11185
|
useCofheTokenDecryptedBalance,
|
|
11186
|
+
useCofheTokenPublicBalance,
|
|
11189
11187
|
useCofheTokensClaimable,
|
|
11190
11188
|
getCofheTokenShieldCallArgs,
|
|
11191
11189
|
useCofheTokenShield,
|
|
@@ -11208,4 +11206,4 @@ export {
|
|
|
11208
11206
|
SettingsPage,
|
|
11209
11207
|
CofheFloatingButtonWithProvider
|
|
11210
11208
|
};
|
|
11211
|
-
//# sourceMappingURL=chunk-
|
|
11209
|
+
//# sourceMappingURL=chunk-DSFIX7QP.js.map
|