@chipi-stack/chipi-react 12.7.0 → 13.0.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.mjs CHANGED
@@ -4,6 +4,7 @@ import { decryptPrivateKey, encryptPrivateKey } from '@chipi-stack/backend';
4
4
  import '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/hooks/useCreateWallet.ts
9
10
  var ChipiContext = createContext(null);
@@ -131,7 +132,7 @@ function useChipiWallet(config) {
131
132
  return failureCount < 3;
132
133
  }
133
134
  });
134
- const walletPublicKey = walletQuery.data?.publicKey;
135
+ const walletPublicKey = walletQuery.data?.wallet.publicKey;
135
136
  const balanceQuery = useQuery({
136
137
  queryKey: ["chipi-wallet-balance", walletPublicKey, defaultToken],
137
138
  queryFn: async () => {
@@ -140,7 +141,7 @@ function useChipiWallet(config) {
140
141
  if (!bearerToken) throw new Error("Bearer token is required");
141
142
  return chipiSDK.getTokenBalance(
142
143
  {
143
- chain: "STARKNET",
144
+ chain: Chain.STARKNET,
144
145
  chainToken: defaultToken,
145
146
  walletPublicKey
146
147
  },
@@ -162,6 +163,7 @@ function useChipiWallet(config) {
162
163
  if (!bearerToken) throw new Error("Bearer token is required");
163
164
  return chipiSDK.createWallet({
164
165
  params: {
166
+ chain: Chain.STARKNET,
165
167
  encryptKey,
166
168
  externalUserId,
167
169
  walletType
@@ -181,8 +183,8 @@ function useChipiWallet(config) {
181
183
  const data = walletQuery.data;
182
184
  return {
183
185
  ...data,
184
- supportsSessionKeys: data.walletType === "CHIPI",
185
- shortAddress: formatAddress(data.publicKey)
186
+ supportsSessionKeys: data.wallet.walletType === "CHIPI",
187
+ shortAddress: formatAddress(data.wallet.publicKey)
186
188
  };
187
189
  }, [walletQuery.data, walletQuery.isLoading]);
188
190
  const formattedBalance = useMemo(() => {
@@ -190,7 +192,7 @@ function useChipiWallet(config) {
190
192
  const num = Number(balanceQuery.data.balance);
191
193
  return num.toLocaleString(void 0, {
192
194
  minimumFractionDigits: 2,
193
- maximumFractionDigits: defaultToken === "ETH" || defaultToken === "STRK" ? 6 : 2
195
+ maximumFractionDigits: defaultToken === ChainToken.ETH || defaultToken === ChainToken.STRK ? 6 : 2
194
196
  });
195
197
  }, [balanceQuery.data, defaultToken]);
196
198
  const refetchWallet = useCallback(async () => {
@@ -654,17 +656,17 @@ function useGetTransactionList(input) {
654
656
  fetchTransactionList
655
657
  };
656
658
  }
657
- function useCreateSkuTransaction() {
659
+ function usePurchaseSku() {
658
660
  const { chipiSDK } = useChipiContext();
659
661
  const mutation = useMutation({
660
- mutationFn: (input) => chipiSDK.createSkuTransaction({
662
+ mutationFn: (input) => chipiSDK.purchaseSku({
661
663
  params: input.params,
662
664
  bearerToken: input.bearerToken
663
665
  })
664
666
  });
665
667
  return {
666
- createSkuTransaction: mutation.mutate,
667
- createSkuTransactionAsync: mutation.mutateAsync,
668
+ purchaseSku: mutation.mutate,
669
+ purchaseSkuAsync: mutation.mutateAsync,
668
670
  data: mutation.data,
669
671
  isLoading: mutation.isPending,
670
672
  isError: mutation.isError,
@@ -673,36 +675,37 @@ function useCreateSkuTransaction() {
673
675
  reset: mutation.reset
674
676
  };
675
677
  }
676
- function useGetSkuTransaction(input) {
678
+ function useGetSkuPurchase(input) {
677
679
  const { chipiSDK } = useChipiContext();
678
680
  const queryClient = useQueryClient();
679
681
  const query = useQuery({
680
- queryKey: ["sku-transaction", input?.id],
682
+ queryKey: ["sku-purchase", input?.id],
681
683
  queryFn: async () => {
682
684
  if (!input?.id) throw new Error("id is required");
683
685
  if (!input?.getBearerToken) throw new Error("getBearerToken is required");
684
686
  const bearerToken = await input.getBearerToken();
685
687
  if (!bearerToken) throw new Error("Bearer token is required");
686
- return chipiSDK.skuTransactions.getSkuTransaction(input.id, bearerToken);
688
+ return chipiSDK.getSkuPurchase(input.id, bearerToken);
687
689
  },
688
690
  enabled: Boolean(input?.id && input?.getBearerToken),
689
691
  ...input?.queryOptions
690
692
  });
691
- const fetchSkuTransaction = async (newInput) => {
693
+ const fetchSkuPurchase = async (newInput) => {
692
694
  return queryClient.fetchQuery({
693
- queryKey: ["sku-transaction", newInput?.id],
695
+ queryKey: ["sku-purchase", newInput?.id],
694
696
  queryFn: async () => {
695
697
  if (!newInput?.id) throw new Error("id is required");
696
- if (!newInput?.getBearerToken) throw new Error("getBearerToken is required");
698
+ if (!newInput?.getBearerToken)
699
+ throw new Error("getBearerToken is required");
697
700
  const bearerToken = await newInput.getBearerToken();
698
701
  if (!bearerToken) throw new Error("Bearer token is required");
699
- return chipiSDK.skuTransactions.getSkuTransaction(newInput.id, bearerToken);
702
+ return chipiSDK.getSkuPurchase(newInput.id, bearerToken);
700
703
  }
701
704
  });
702
705
  };
703
706
  return {
704
707
  ...query,
705
- fetchSkuTransaction
708
+ fetchSkuPurchase
706
709
  };
707
710
  }
708
711
  function useGetSkuList(input) {
@@ -1174,6 +1177,6 @@ function useExecuteWithSession() {
1174
1177
  };
1175
1178
  }
1176
1179
 
1177
- export { useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useMigrateWalletToPasskey, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
1180
+ export { useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
1178
1181
  //# sourceMappingURL=hooks.mjs.map
1179
1182
  //# sourceMappingURL=hooks.mjs.map