Skip to content

Commit

Permalink
finally it worksss!! front respond begin to end
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Oct 22, 2023
1 parent 973b3f6 commit b526043
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 119 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
$autonomousSwap = _autonomousSwap;
})
mainOrder.update(() => {
return ({
finalTransaction: null
})
});
</script>

Expand Down
75 changes: 42 additions & 33 deletions src/components/CreatorSwap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
</script>

<SwapSection>
<div>
<h1>CREATOR: {$mainOrder.creator}</h1>
{#if $creatorState == CreatorState.WaitingForPartnerJoin}
<CreationStep isCreator={true}/>
{:else if $creatorState == CreatorState.AllowingAutonomousSwap || $creatorState == CreatorState.WaitingPartnerAllowance}
<AllowanceStep isCreator={true}/>
{:else if $creatorState == CreatorState.SendingTokens}
<p>teste4</p>
{:else if $creatorState == CreatorState.WaitingPartnersTransfer}
<p>teste5d</p>
{:else if $creatorState == CreatorState.Completed}
<p>teste6</p>
{/if}
</div>
<!-- {#if $mainOrder.finalTransaction == null} -->
{#if !($partnerState == PartnerState.Completed && $creatorState == CreatorState.Completed)}
<div>
<h1>CREATOR: {$mainOrder.creator}</h1>
{#if $creatorState == CreatorState.WaitingForPartnerJoin}
<CreationStep isCreator={true}/>
{:else if $creatorState == CreatorState.AllowingAutonomousSwap || $creatorState == CreatorState.WaitingPartnerAllowance}
<AllowanceStep isCreator={true}/>
{:else if $creatorState == CreatorState.SendingTokens}
<FinalStep isCreator={true} />
{:else if $creatorState == CreatorState.WaitingPartnersTransfer}
<p>teste5d</p>
{:else if $creatorState == CreatorState.Completed}
<p>teste6</p>
{/if}
</div>

<div>
<h1>PARTNER: {$mainOrder.partner ? $mainOrder.partner : 'waiting...'}</h1>
{#if $partnerState == null}
<WaitingJoin>PARTNER</WaitingJoin>
{:else if $partnerState == PartnerState.WaitingFirstConfirmation}
<CreationStep on:click={() => {$creatorState = CreatorState.AllowingAutonomousSwap; $partnerState = PartnerState.AllowingAutonomousSwap}}/>
{:else if $partnerState == PartnerState.AllowingAutonomousSwap || $partnerState == PartnerState.WaitingCreatorAllowance}
<AllowanceStep on:click={() => {$creatorState = CreatorState.SendingTokens; $partnerState = PartnerState.WaitingCreatorsFunding}}/>
<!-- {#if $creatorState == CreatorState.WaitingPartnerAllowance && $partnerState == PartnerState.WaitingCreatorAllowance}
{/if} -->
{:else if $partnerState == PartnerState.WaitingCreatorsFunding}
<p>teste4</p>
{:else if $partnerState == PartnerState.SendingTokens}
<p>teste5</p>
{:else if $partnerState == PartnerState.Completed}
<p>teste6</p>
{/if}
</div>
<div>
<h1>PARTNER: {$mainOrder.partner ? $mainOrder.partner : 'waiting...'}</h1>
{#if $partnerState == null}
<WaitingJoin>PARTNER</WaitingJoin>
{:else if $partnerState == PartnerState.WaitingFirstConfirmation}
<CreationStep on:click={() => {$creatorState = CreatorState.AllowingAutonomousSwap; $partnerState = PartnerState.AllowingAutonomousSwap}}/>
{:else if $partnerState == PartnerState.AllowingAutonomousSwap || $partnerState == PartnerState.WaitingCreatorAllowance}
<AllowanceStep />
{#if $creatorState == CreatorState.WaitingPartnerAllowance && $partnerState == PartnerState.WaitingCreatorAllowance}
<Button on:click={() => {$creatorState = CreatorState.SendingTokens; $partnerState = PartnerState.WaitingCreatorsFunding}}>Next Step</Button>
{/if}
{:else if $partnerState == PartnerState.WaitingCreatorsFunding}
<FinalStep />
{:else if $partnerState == PartnerState.Completed}
<p>teste6</p>
{/if}
</div>

{:else}
<div>
<h1 class="text-6xl">PARABÉNS, DEU CERTOOO!!</h1>
<h1 class="text-4xl">{$mainOrder.finalTransaction}</h1>
</div>
{/if}
</SwapSection>
70 changes: 17 additions & 53 deletions src/components/ReturnToOrder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
</script>
Expand Down
61 changes: 33 additions & 28 deletions src/components/creator/AllowanceStep.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
console.log(tokenAddress, interfaceID, quantity, tokenId)
let contract: IERC20 & IERC721 & IERC1155 & ethers.BaseContract;
Expand Down Expand Up @@ -122,23 +130,20 @@
}
}
$: console.log(creatorAllowance, partnerAllowance)
</script>


{#if isCreator}
{#if creatorAllowance}
<p>APROVADO CARAMBA</p>
<p>APROVADO CARAMBAaaaaa</p>
{:else}
<Button on:click={() => requestAllowance($creatorSubOrder.token)}>Give Allowance</Button>
{/if}

{:else}
{#if partnerAllowance}
<p>APROVADO CARAMBA</p>
{#if creatorAllowance && partnerAllowance}
<Button on:click>Next Step</Button>
{/if}
{:else}
Awaiting Allowance ...
{/if}
Expand Down
61 changes: 61 additions & 0 deletions src/components/creator/FinalStep.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<script lang="ts">
import { CreatorState, PartnerState } from "../../lib/enums.js";
import { autonomousSwap, mainOrder, partnerSubOrder, creatorState, partnerState, creatorSubOrder, signer } from "../../lib/stores.js";
import Button from "../base/Button.svelte";
import { ContractTransactionResponse, ethers } from "ethers";
import { onMount, onDestroy } from "svelte";
let _autonomousSwap: AutonomousSwapContract;
const unsubscribe = autonomousSwap.subscribe((value) => {
_autonomousSwap = value;
})
onDestroy(unsubscribe);
export let isCreator = false;
let creatorFinished = false;
let partnerFinished = false;
if(isCreator){
_autonomousSwap.on('StepCompleted' as any, async (orderId, who, newStatus, event) => {
if (orderId == $mainOrder.orderId && who == $mainOrder.partner){
if (newStatus == 3){
console.log(event)
$partnerState = PartnerState.Completed;
$creatorState = CreatorState.Completed;
$mainOrder.finalTransaction = event.transactionHash;
partnerFinished = true;
_autonomousSwap.removeAllListeners();
}
}
});
}
async function transferFundsToSwap(){
const transactionResponse: ContractTransactionResponse = await _autonomousSwap.transferFundsToSwap($mainOrder.orderId);
const transactionReceipt = await transactionResponse.wait();
if (transactionReceipt.status == 1){
creatorFinished = true;
}
}
</script>


{#if isCreator}
{#if creatorFinished}
<p>AGORA É SÓ ESPERAR PAE</p>
{:else}
<Button on:click={() => transferFundsToSwap()}>Send Funds</Button>
{/if}

{:else}
{#if partnerFinished}
<p>TERMINOOOUU!!!!!!!!!!</p>
{:else}
Awaiting transaction ...
{/if}
{/if}
2 changes: 1 addition & 1 deletion src/components/creator/WaitingJoin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b526043

Please sign in to comment.