diff --git a/.changeset/two-zebras-sort.md b/.changeset/two-zebras-sort.md new file mode 100644 index 000000000..967a12d2c --- /dev/null +++ b/.changeset/two-zebras-sort.md @@ -0,0 +1,5 @@ +--- +"@ark-project/react": patch +--- + +Add missing comparison for approve erc20 diff --git a/packages/core/src/contracts.ts b/packages/core/src/contracts.ts index 1ca5d7f63..95a0a3e83 100644 --- a/packages/core/src/contracts.ts +++ b/packages/core/src/contracts.ts @@ -1,28 +1,22 @@ // This file is auto-generated. Do not edit directly. export const GOERLI_CONTRACTS = { - nftContract: - "0x22411b480425fe6e627fdf4d1b6ac7f8567314ada5617a0a6d8ef3e74b69436", - messaging: - "0x2c3d3e0c37d29364a13ba8cff046e7bc5624655a72526961876a1c8bb3f63c8", - executor: "0x73148536f8ea9546e92761d11515548cc433df46883d5ee98871a6f63a0bbbc", - orderbook: "0x66f1e6acf9bdbd23837b2eea271430298b355c506978edb132737e7fcb6b310" + "nftContract": "0x22411b480425fe6e627fdf4d1b6ac7f8567314ada5617a0a6d8ef3e74b69436", + "messaging": "0x2c3d3e0c37d29364a13ba8cff046e7bc5624655a72526961876a1c8bb3f63c8", + "executor": "0x73148536f8ea9546e92761d11515548cc433df46883d5ee98871a6f63a0bbbc", + "orderbook": "0x66f1e6acf9bdbd23837b2eea271430298b355c506978edb132737e7fcb6b310" }; export const SEPOLIA_CONTRACTS = {}; export const MAINNET_CONTRACTS = { - nftContract: - "0x32d99485b22f2e58c8a0206d3b3bb259997ff0db70cffd25585d7dd9a5b0546", - messaging: - "0x57d45cc46de463f7ae63b74ce9b6b6b496a1178b02e7ad04d7c307caa698b7b", - executor: "0x7b42945bc47001db92fe1b9739d753925263f2f1036c2ae1f87536c916ee6a", - orderbook: "0x5b0b2069b9567757fea9bfd4a2e588a151b8892ecb0e7bdcf0b7eeaefb86a60" + "nftContract": "0x32d99485b22f2e58c8a0206d3b3bb259997ff0db70cffd25585d7dd9a5b0546", + "messaging": "0x57d45cc46de463f7ae63b74ce9b6b6b496a1178b02e7ad04d7c307caa698b7b", + "executor": "0x7b42945bc47001db92fe1b9739d753925263f2f1036c2ae1f87536c916ee6a", + "orderbook": "0x5b0b2069b9567757fea9bfd4a2e588a151b8892ecb0e7bdcf0b7eeaefb86a60" }; export const DEV_CONTRACTS = { - messaging: - "0x2c8ae5699e492093e0f06225fb41050286fd40756603335e5c832f1ab90911c", - executor: "0x22419164936022963b861d4ecaf20c72207183d9a86fd8bbe4e6a584da3a768", - nftContract: - "0x1903a865f4472b09b13dbf3d24f42271d2803b90f2029c807d6c4400b5042", - eth: "0x7b8fc5c78bf249bb4173ef45267da1a710c65d76bb9ff03deb6b8fc21f35ba4", - orderbook: "0x2426ebb057f812c38e9870cd68c8f1f0cfea48c34b1017258e4e66c208ae14" + "messaging": "0x2c8ae5699e492093e0f06225fb41050286fd40756603335e5c832f1ab90911c", + "executor": "0x22419164936022963b861d4ecaf20c72207183d9a86fd8bbe4e6a584da3a768", + "nftContract": "0x1903a865f4472b09b13dbf3d24f42271d2803b90f2029c807d6c4400b5042", + "eth": "0x7b8fc5c78bf249bb4173ef45267da1a710c65d76bb9ff03deb6b8fc21f35ba4", + "orderbook": "0x2426ebb057f812c38e9870cd68c8f1f0cfea48c34b1017258e4e66c208ae14" }; diff --git a/packages/react/src/hooks/useApproveERC20.ts b/packages/react/src/hooks/useApproveERC20.ts index 077e4a6a0..d36765a94 100644 --- a/packages/react/src/hooks/useApproveERC20.ts +++ b/packages/react/src/hooks/useApproveERC20.ts @@ -53,12 +53,13 @@ function useApproveERC20() { parameters.starknetAccount, parameters.currencyAddress ); - console.log("allowance", allowance); - return await approveERC20Core(config as Config, { - starknetAccount: parameters.starknetAccount, - contractAddress: parameters.currencyAddress.toString(), - amount: parameters.startAmount - }); + if (Number(BigInt(allowance)) < Number(BigInt(parameters.startAmount))) { + return await approveERC20Core(config as Config, { + starknetAccount: parameters.starknetAccount, + contractAddress: parameters.currencyAddress.toString(), + amount: parameters.startAmount + }); + } } return { approveERC20, getAllowance }; } diff --git a/packages/react/src/hooks/useFulfillListing.ts b/packages/react/src/hooks/useFulfillListing.ts index c552b021c..ff761f25a 100644 --- a/packages/react/src/hooks/useFulfillListing.ts +++ b/packages/react/src/hooks/useFulfillListing.ts @@ -20,7 +20,7 @@ export type fulfillListingParameters = ApproveERC20Parameters & function useFulfillListing() { const [status, setStatus] = useState("idle"); const [stepStatus, setStepStatus] = useState("idle"); - const { approveERC20, getAllowance } = useApproveERC20(); + const { approveERC20 } = useApproveERC20(); const owner = useOwner(); const arkAccount = useBurnerWallet(); const config = useConfig(); @@ -29,14 +29,10 @@ function useFulfillListing() { if (!arkAccount) throw new Error("No burner wallet."); try { setStatus("loading"); - const allowance = await getAllowance( - parameters.starknetAccount, - parameters.currencyAddress || config?.starknetContracts.eth - ); setStepStatus("approving"); await approveERC20({ starknetAccount: parameters.starknetAccount, - startAmount: Number(parameters.startAmount) + Number(allowance), + startAmount: Number(parameters.startAmount), currencyAddress: parameters.currencyAddress || config?.starknetContracts.eth });