Skip to content

Commit

Permalink
fix(approve): add comparison to check if approve is needed (#350)
Browse files Browse the repository at this point in the history
## What type of PR is this? (check all applicable)

- [x] 🐛 Bug Fix (`fix:`)
  • Loading branch information
kwiss authored Apr 27, 2024
1 parent f55df4e commit 572c5f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-zebras-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ark-project/react": patch
---

Add missing comparison for approve erc20
32 changes: 13 additions & 19 deletions packages/core/src/contracts.ts
Original file line number Diff line number Diff line change
@@ -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"
};
13 changes: 7 additions & 6 deletions packages/react/src/hooks/useApproveERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/hooks/useFulfillListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type fulfillListingParameters = ApproveERC20Parameters &
function useFulfillListing() {
const [status, setStatus] = useState<Status>("idle");
const [stepStatus, setStepStatus] = useState<StepStatus>("idle");
const { approveERC20, getAllowance } = useApproveERC20();
const { approveERC20 } = useApproveERC20();
const owner = useOwner();
const arkAccount = useBurnerWallet();
const config = useConfig();
Expand All @@ -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
});
Expand Down

0 comments on commit 572c5f3

Please sign in to comment.