@pyratzlabs/react-fhevm-utils 2.0.3 → 2.0.4

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.
@@ -3,7 +3,7 @@ export interface EncryptedTransferProps {
3
3
  tokenAddress: Address;
4
4
  }
5
5
  export declare const useEncryptedTransfer: ({ tokenAddress, }: EncryptedTransferProps) => {
6
- transfer: (to: Address, handles: Uint8Array[], inputProof: Uint8Array) => void;
6
+ transfer: (to: Address, handles: Uint8Array[], inputProof: Uint8Array, transferFee?: number) => void;
7
7
  isLoading: boolean;
8
8
  isFailed: boolean;
9
9
  isSuccess: boolean;
@@ -1,19 +1,23 @@
1
1
  import { usePerformTransaction } from "./usePerformTransaction";
2
2
  import { encryptedABI } from "../types/encryptedABI";
3
3
  import { toHexString } from "../utils/string.utils";
4
+ import { decimalToToken } from "../utils/number.utils";
4
5
  export const useEncryptedTransfer = ({ tokenAddress, }) => {
5
6
  const { perform, isLoading, isFailed, isSuccess, error } = usePerformTransaction({
6
7
  abi: encryptedABI,
7
8
  address: tokenAddress,
8
9
  functionName: "confidentialTransfer",
9
10
  });
10
- const transfer = (to, handles, inputProof) => {
11
+ const transfer = (to, handles, inputProof, transferFee) => {
11
12
  if (handles.length === 0)
12
13
  throw new Error("Bad handles format");
14
+ if (!transferFee)
15
+ throw new Error("TRANSFER: No transfer fee provided");
13
16
  const encryptedAmount = toHexString(handles[0]);
14
17
  const proof = toHexString(inputProof);
15
18
  perform({
16
19
  args: [to, encryptedAmount, proof],
20
+ value: decimalToToken(transferFee, 18),
17
21
  });
18
22
  };
19
23
  return { transfer, isLoading, isFailed, isSuccess, error };
@@ -0,0 +1,2 @@
1
+ export declare const tokenToDecimal: (value: bigint, decimals: number) => number;
2
+ export declare const decimalToToken: (value: number, decimals: number) => bigint;
@@ -0,0 +1,3 @@
1
+ import { formatUnits, parseUnits } from "viem";
2
+ export const tokenToDecimal = (value, decimals) => Number(formatUnits(value, decimals));
3
+ export const decimalToToken = (value, decimals) => parseUnits(value.toString(), decimals);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyratzlabs/react-fhevm-utils",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "React hooks and utilities for Fhevmjs",
5
5
  "main": "dist/index.js",
6
6
  "files": [