@chipi-stack/chipi-react 12.8.0 → 13.1.0
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/hooks.d.mts +33 -33
- package/dist/hooks.d.ts +33 -33
- package/dist/hooks.js +19 -16
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +18 -15
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo, useCallback, useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryClientProvider, useMutation, useQueryClient, useQuery, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { ChipiSDK, decryptPrivateKey, encryptPrivateKey } from '@chipi-stack/backend';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
import { createWalletPasskey, getWalletEncryptKey } from '@chipi-stack/chipi-passkey';
|
|
6
6
|
import { ChipiApiError } from '@chipi-stack/shared';
|
|
7
|
+
import { Chain, ChainToken } from '@chipi-stack/types';
|
|
7
8
|
|
|
8
9
|
// src/context/ChipiProvider.tsx
|
|
9
10
|
var ChipiContext = createContext(null);
|
|
@@ -171,7 +172,7 @@ function useChipiWallet(config) {
|
|
|
171
172
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
172
173
|
return chipiSDK.getTokenBalance(
|
|
173
174
|
{
|
|
174
|
-
chain:
|
|
175
|
+
chain: Chain.STARKNET,
|
|
175
176
|
chainToken: defaultToken,
|
|
176
177
|
walletPublicKey
|
|
177
178
|
},
|
|
@@ -193,6 +194,7 @@ function useChipiWallet(config) {
|
|
|
193
194
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
194
195
|
return chipiSDK.createWallet({
|
|
195
196
|
params: {
|
|
197
|
+
chain: Chain.STARKNET,
|
|
196
198
|
encryptKey,
|
|
197
199
|
externalUserId,
|
|
198
200
|
walletType
|
|
@@ -221,7 +223,7 @@ function useChipiWallet(config) {
|
|
|
221
223
|
const num = Number(balanceQuery.data.balance);
|
|
222
224
|
return num.toLocaleString(void 0, {
|
|
223
225
|
minimumFractionDigits: 2,
|
|
224
|
-
maximumFractionDigits: defaultToken ===
|
|
226
|
+
maximumFractionDigits: defaultToken === ChainToken.ETH || defaultToken === ChainToken.STRK ? 6 : 2
|
|
225
227
|
});
|
|
226
228
|
}, [balanceQuery.data, defaultToken]);
|
|
227
229
|
const refetchWallet = useCallback(async () => {
|
|
@@ -685,17 +687,17 @@ function useGetTransactionList(input) {
|
|
|
685
687
|
fetchTransactionList
|
|
686
688
|
};
|
|
687
689
|
}
|
|
688
|
-
function
|
|
690
|
+
function usePurchaseSku() {
|
|
689
691
|
const { chipiSDK } = useChipiContext();
|
|
690
692
|
const mutation = useMutation({
|
|
691
|
-
mutationFn: (input) => chipiSDK.
|
|
693
|
+
mutationFn: (input) => chipiSDK.purchaseSku({
|
|
692
694
|
params: input.params,
|
|
693
695
|
bearerToken: input.bearerToken
|
|
694
696
|
})
|
|
695
697
|
});
|
|
696
698
|
return {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
+
purchaseSku: mutation.mutate,
|
|
700
|
+
purchaseSkuAsync: mutation.mutateAsync,
|
|
699
701
|
data: mutation.data,
|
|
700
702
|
isLoading: mutation.isPending,
|
|
701
703
|
isError: mutation.isError,
|
|
@@ -704,36 +706,37 @@ function useCreateSkuTransaction() {
|
|
|
704
706
|
reset: mutation.reset
|
|
705
707
|
};
|
|
706
708
|
}
|
|
707
|
-
function
|
|
709
|
+
function useGetSkuPurchase(input) {
|
|
708
710
|
const { chipiSDK } = useChipiContext();
|
|
709
711
|
const queryClient = useQueryClient();
|
|
710
712
|
const query = useQuery({
|
|
711
|
-
queryKey: ["sku-
|
|
713
|
+
queryKey: ["sku-purchase", input?.id],
|
|
712
714
|
queryFn: async () => {
|
|
713
715
|
if (!input?.id) throw new Error("id is required");
|
|
714
716
|
if (!input?.getBearerToken) throw new Error("getBearerToken is required");
|
|
715
717
|
const bearerToken = await input.getBearerToken();
|
|
716
718
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
717
|
-
return chipiSDK.
|
|
719
|
+
return chipiSDK.getSkuPurchase(input.id, bearerToken);
|
|
718
720
|
},
|
|
719
721
|
enabled: Boolean(input?.id && input?.getBearerToken),
|
|
720
722
|
...input?.queryOptions
|
|
721
723
|
});
|
|
722
|
-
const
|
|
724
|
+
const fetchSkuPurchase = async (newInput) => {
|
|
723
725
|
return queryClient.fetchQuery({
|
|
724
|
-
queryKey: ["sku-
|
|
726
|
+
queryKey: ["sku-purchase", newInput?.id],
|
|
725
727
|
queryFn: async () => {
|
|
726
728
|
if (!newInput?.id) throw new Error("id is required");
|
|
727
|
-
if (!newInput?.getBearerToken)
|
|
729
|
+
if (!newInput?.getBearerToken)
|
|
730
|
+
throw new Error("getBearerToken is required");
|
|
728
731
|
const bearerToken = await newInput.getBearerToken();
|
|
729
732
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
730
|
-
return chipiSDK.
|
|
733
|
+
return chipiSDK.getSkuPurchase(newInput.id, bearerToken);
|
|
731
734
|
}
|
|
732
735
|
});
|
|
733
736
|
};
|
|
734
737
|
return {
|
|
735
738
|
...query,
|
|
736
|
-
|
|
739
|
+
fetchSkuPurchase
|
|
737
740
|
};
|
|
738
741
|
}
|
|
739
742
|
function useGetSkuList(input) {
|
|
@@ -1205,6 +1208,6 @@ function useExecuteWithSession() {
|
|
|
1205
1208
|
};
|
|
1206
1209
|
}
|
|
1207
1210
|
|
|
1208
|
-
export { ChipiProvider, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiContext, useChipiSession, useChipiWallet, useCreateSessionKey,
|
|
1211
|
+
export { ChipiProvider, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiContext, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
|
1209
1212
|
//# sourceMappingURL=index.mjs.map
|
|
1210
1213
|
//# sourceMappingURL=index.mjs.map
|