diff --git a/README.md b/README.md index 954188f..a365460 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ That is it! Done :D ===================================================== For you to test: -Random ERC20 token: 0x2E6dd9771E607259F9F52AcD2A99Ba7A6483952d -Random ERC721 token: 0xb829d0931FE3eFDE1E5E64BF8719ec4DFF51c9Da -Random ERC1155 token: 0x97C998bDbBc40a257FdE53e781de949c300F5b20 +Random ERC20 token: 0x2E6dd9771E607259F9F52AcD2A99Ba7A6483952d +Random ERC721 token: 0xb829d0931FE3eFDE1E5E64BF8719ec4DFF51c9Da +Random ERC1155 token: 0x97C998bDbBc40a257FdE53e781de949c300F5b20 **Deployed links:** @@ -76,7 +76,7 @@ Verification link: https://sepolia.etherscan.io/address/0x9a642b656ea04452aba6e8 **Scroll** flattened deployment: 0xcf1D6e6a704b0717D19dD4740CA0aD7aaE2415AD Verification link: https://sepolia-blockscout.scroll.io/address/0xcf1D6e6a704b0717D19dD4740CA0aD7aaE2415AD/contracts#address-tabs Verification link: https://sepolia.scrollscan.dev/address/0xcf1d6e6a704b0717d19dd4740ca0ad7aae2415ad#code - + **Filecoin** flattened deployment: 0xcf1D6e6a704b0717D19dD4740CA0aD7aaE2415AD Verification link (solidity 8.19): https://calibration.filfox.info/en/address/0xa5747753Ef82F9140c7C05C6179bA7a5e86eB345?t=3 diff --git a/src/App.svelte b/src/App.svelte index 61de74c..8bb346f 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -32,6 +32,11 @@ $autonomousSwap = _autonomousSwap; }) + mainOrder.update(() => { + return ({ + finalTransaction: null + }) + }); diff --git a/src/components/CreatorSwap.svelte b/src/components/CreatorSwap.svelte index f31e6ae..99be9f4 100644 --- a/src/components/CreatorSwap.svelte +++ b/src/components/CreatorSwap.svelte @@ -8,43 +8,52 @@ import WaitingJoin from "./creator/WaitingJoin.svelte"; import { onMount, onDestroy } from "svelte"; import AllowanceStep from "./creator/AllowanceStep.svelte"; + import Button from "./base/Button.svelte"; + import FinalStep from "./creator/FinalStep.svelte"; -
-

CREATOR: {$mainOrder.creator}

- {#if $creatorState == CreatorState.WaitingForPartnerJoin} - - {:else if $creatorState == CreatorState.AllowingAutonomousSwap || $creatorState == CreatorState.WaitingPartnerAllowance} - - {:else if $creatorState == CreatorState.SendingTokens} -

teste4

- {:else if $creatorState == CreatorState.WaitingPartnersTransfer} -

teste5d

- {:else if $creatorState == CreatorState.Completed} -

teste6

- {/if} -
+ + {#if !($partnerState == PartnerState.Completed && $creatorState == CreatorState.Completed)} +
+

CREATOR: {$mainOrder.creator}

+ {#if $creatorState == CreatorState.WaitingForPartnerJoin} + + {:else if $creatorState == CreatorState.AllowingAutonomousSwap || $creatorState == CreatorState.WaitingPartnerAllowance} + + {:else if $creatorState == CreatorState.SendingTokens} + + {:else if $creatorState == CreatorState.WaitingPartnersTransfer} +

teste5d

+ {:else if $creatorState == CreatorState.Completed} +

teste6

+ {/if} +
-
-

PARTNER: {$mainOrder.partner ? $mainOrder.partner : 'waiting...'}

- {#if $partnerState == null} - PARTNER - {:else if $partnerState == PartnerState.WaitingFirstConfirmation} - {$creatorState = CreatorState.AllowingAutonomousSwap; $partnerState = PartnerState.AllowingAutonomousSwap}}/> - {:else if $partnerState == PartnerState.AllowingAutonomousSwap || $partnerState == PartnerState.WaitingCreatorAllowance} - {$creatorState = CreatorState.SendingTokens; $partnerState = PartnerState.WaitingCreatorsFunding}}/> - - {:else if $partnerState == PartnerState.WaitingCreatorsFunding} -

teste4

- {:else if $partnerState == PartnerState.SendingTokens} -

teste5

- {:else if $partnerState == PartnerState.Completed} -

teste6

- {/if} -
+
+

PARTNER: {$mainOrder.partner ? $mainOrder.partner : 'waiting...'}

+ {#if $partnerState == null} + PARTNER + {:else if $partnerState == PartnerState.WaitingFirstConfirmation} + {$creatorState = CreatorState.AllowingAutonomousSwap; $partnerState = PartnerState.AllowingAutonomousSwap}}/> + {:else if $partnerState == PartnerState.AllowingAutonomousSwap || $partnerState == PartnerState.WaitingCreatorAllowance} + + {#if $creatorState == CreatorState.WaitingPartnerAllowance && $partnerState == PartnerState.WaitingCreatorAllowance} + + {/if} + {:else if $partnerState == PartnerState.WaitingCreatorsFunding} + + {:else if $partnerState == PartnerState.Completed} +

teste6

+ {/if} +
+ + {:else} +
+

PARABÉNS, DEU CERTOOO!!

+

{$mainOrder.finalTransaction}

+
+ {/if}
\ No newline at end of file diff --git a/src/components/ReturnToOrder.svelte b/src/components/ReturnToOrder.svelte index 084cd85..9018f2f 100644 --- a/src/components/ReturnToOrder.svelte +++ b/src/components/ReturnToOrder.svelte @@ -63,7 +63,16 @@ }) }); - } else + if ($creatorSubOrder.individualStatus == 1) { + $creatorState = CreatorState.AllowingAutonomousSwap; + $partnerState = PartnerState.AllowingAutonomousSwap; + } else + if ($creatorSubOrder.individualStatus == 2) { + $creatorState = CreatorState.WaitingPartnersTransfer; + $partnerState = PartnerState.WaitingCreatorsFunding; + } + $generalState = GeneralState.OrderCreated; + } else if (partner == _signer) { let _creatorSubOrder = await _autonomousSwap.getSubOrderByUser(creator, orderId); let _partnerSubOrder = await _autonomousSwap.getSubOrderByUser(partner, orderId); @@ -100,64 +109,19 @@ isCreator: false }) }); + + if ($partnerSubOrder.individualStatus == 1) { + $creatorState = CreatorState.AllowingAutonomousSwap; + $partnerState = PartnerState.AllowingAutonomousSwap; + } + $generalState = GeneralState.OrderJoined; + } else { error = "Invalid orderId"; console.log(error) throw new Error(error); return } - - - console.log($mainOrder) - console.log($creatorSubOrder) - console.log($partnerSubOrder) - - if ($creatorSubOrder.) - - - // let _subOrder: [BytesLike, AddressLike, BigNumberish, BigNumberish]; - // _subOrder = [ - // orderId, - // token, - // tokenId, - // quantity - // ]; - - // const transactionResponse: ContractTransactionResponse = await _autonomousSwap.joinsOrder(..._subOrder); - // const transactionReceipt = await transactionResponse.wait(); - // const eventLog = transactionReceipt.logs[0] as ethers.EventLog; - // const filter = { - // topics: [...eventLog.topics], - // data: eventLog.data - // } - // const logOutput = _autonomousSwap.interface.parseLog(filter).args; - // // console.log(logOutput) - - // let { creator, } = await _autonomousSwap.getOrderMembersById(logOutput.orderId as BytesLike); - // console.log(creator) - - // mainOrder.update(() => { - // return ({ - // orderId: logOutput.orderId, - // creator, - // partner: logOutput.who, - // isActive: true, - // isCreator: false - // }) - // }); - - // partnerSubOrder.update(() => { - // return ({ - // token, - // interfaceID, - // tokenId, - // quantity, - // individualStatus: logOutput.newStatus - // }) - // }) - - // $partnerState = PartnerState.WaitingFirstConfirmation; - // $generalState = GeneralState.OrderJoined; } diff --git a/src/components/creator/AllowanceStep.svelte b/src/components/creator/AllowanceStep.svelte index 738100f..4877d71 100644 --- a/src/components/creator/AllowanceStep.svelte +++ b/src/components/creator/AllowanceStep.svelte @@ -20,36 +20,44 @@ ERC1155: '0xd9b67a26' }; let interfaceID; - let interval1; - let interval2; - if (isCreator){ interfaceID = $creatorSubOrder.interfaceID; - - interval1 = setInterval( async () => { - let response = await isAllowed($creatorSubOrder.token, $mainOrder.creator, interfaceID, $creatorSubOrder.quantity, $creatorSubOrder.tokenId) - if (response) creatorAllowance = true; - console.log(partnerAllowance) - }, 1000); - + creatorResponse() } else { interfaceID = $partnerSubOrder.interfaceID; - - interval2 = setInterval( async () => { - let response = await isAllowed($partnerSubOrder.token, $mainOrder.partner, interfaceID, $partnerSubOrder.quantity, $partnerSubOrder.tokenId) - if (response) partnerAllowance = true; - console.log(partnerAllowance) - }, 1000); + partnerResponse() + } + + + async function creatorResponse(){ + if (creatorAllowance) return; + let response = await isAllowed($creatorSubOrder.token, $mainOrder.creator, interfaceID, $creatorSubOrder.quantity, $creatorSubOrder.tokenId) + console.log(response) + if (response) { + creatorAllowance = true; + $creatorState = CreatorState.WaitingPartnerAllowance; + } + console.log(partnerAllowance) + + setTimeout(creatorResponse, 1000); } - - if (partnerAllowance) {clearInterval(interval1); $creatorState = CreatorState.WaitingPartnerAllowance} - if (creatorAllowance) {clearInterval(interval2); $partnerState = PartnerState.WaitingCreatorAllowance} - // onMount(async ()=>{ -// creatorAllowance = await isAllowed($creatorSubOrder.token, interfaceID, $creatorSubOrder.quantity, $creatorSubOrder.tokenId) -// console.log(creatorAllowance) -// }) + async function partnerResponse(){ + if (partnerAllowance) return; + let response = await isAllowed($partnerSubOrder.token, $mainOrder.partner, interfaceID, $partnerSubOrder.quantity, $partnerSubOrder.tokenId) + console.log(response) + if (response) { + partnerAllowance = true; + $partnerState = PartnerState.WaitingCreatorAllowance; + } + console.log(partnerAllowance) + + setTimeout(partnerResponse, 1000); + } + + + async function isAllowed(tokenAddress, owner, interfaceID, quantity, tokenId):Promise { console.log(tokenAddress, interfaceID, quantity, tokenId) let contract: IERC20 & IERC721 & IERC1155 & ethers.BaseContract; @@ -122,13 +130,13 @@ } } - + $: console.log(creatorAllowance, partnerAllowance) {#if isCreator} {#if creatorAllowance} -

APROVADO CARAMBA

+

APROVADO CARAMBAaaaaa

{:else} {/if} @@ -136,9 +144,6 @@ {:else} {#if partnerAllowance}

APROVADO CARAMBA

- {#if creatorAllowance && partnerAllowance} - - {/if} {:else} Awaiting Allowance ... {/if} diff --git a/src/components/creator/FinalStep.svelte b/src/components/creator/FinalStep.svelte new file mode 100644 index 0000000..fcd91c7 --- /dev/null +++ b/src/components/creator/FinalStep.svelte @@ -0,0 +1,61 @@ + + + +{#if isCreator} + {#if creatorFinished} +

AGORA É SÓ ESPERAR PAE

+ {:else} + + {/if} + +{:else} + {#if partnerFinished} +

TERMINOOOUU!!!!!!!!!!

+ {:else} + Awaiting transaction ... + {/if} +{/if} \ No newline at end of file diff --git a/src/components/creator/WaitingJoin.svelte b/src/components/creator/WaitingJoin.svelte index 2c1c492..c04e647 100644 --- a/src/components/creator/WaitingJoin.svelte +++ b/src/components/creator/WaitingJoin.svelte @@ -11,7 +11,7 @@ onDestroy(unsubscribe); - _autonomousSwap.once('StepCompleted' as any, async (orderId, who, newStatus, event) => { + _autonomousSwap.on('StepCompleted' as any, async (orderId, who, newStatus, event) => { if (orderId == $mainOrder.orderId && who != $mainOrder.creator){ let result = await _autonomousSwap.getSubOrderByUser(who, orderId);