Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | <svelte:options customElement="st-contracts" /> <script lang="ts"> import { onMount } from "svelte"; import Button from "$ui/button/src/button.svelte"; import Loader from "$ui/loader/src/loader.svelte"; import type { Contract } from "$models/contract"; let isLoading = true; let contracts: Contract[]; onMount(async () => { const options = { headers: { "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`, }, }; fetch(`${import.meta.env.VITE_API_URL}/my/contracts`, options) .then((response) => response.json()) .then((response) => { contracts = response.data.map((contract) => { return { id: contract.id, faction: { symbol: contract.factionSymbol, }, type: contract.type, terms: { deadline: new Date(contract.terms.deadline), payment: { onAccepted: contract.terms.payment.onAccepted, onFulfilled: contract.terms.payment.onFulfilled, }, deliver: contract.terms.deliver.map((deliver) => { return { trade: { symbol: deliver.tradeSymbol }, destination: { symbol: deliver.destinationSymbol }, unitsRequired: deliver.unitsRequired, unitsFulfilled: deliver.unitsFulfilled, }; }), }, accepted: contract.accepted, fulfilled: contract.fulfilled, expirationDate: new Date(contract.expiration), deadlineToAccept: new Date(contract.deadlineToAccept), }; }); isLoading = false; }) .catch((error) => { // eslint-disable-next-line no-console console.error(error); isLoading = false; }); }); async function accept(id: string) { // eslint-disable-next-line no-console console.log(`accept contract ${id}`); const options = { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`, }, }; await fetch(`${import.meta.env.VITE_API_URL}/my/contracts/${id}/accept`, options) .then((response) => response.json()) .then(() => { window.location.reload(); }) // eslint-disable-next-line no-console .catch((error) => console.error(error)); return null; } </script> {#if isLoading} <Loader /> {:else} <h2>Contracts</h2> <table> <thead> <tr> <th>Contract</th> <th>Terms</th> <th>Accepted</th> <th>Fulfilled</th> <th>Expiration Date</th> <th>Deadline to Accept</th> <th>Action</th> </tr> </thead> <tbody> {#each contracts as contract} <tr> <td> <div> <span>{contract.faction.symbol}</span> <span>{contract.type}</span> </div> </td> <td> <div> <span>Payment</span> <span>{contract.terms.payment.onAccepted}</span> <span>{contract.terms.payment.onFulfilled}</span> </div> {#each contract.terms.deliver as deliver} <div> <span>Deliver</span> <span>{deliver.trade.symbol}</span> <span>{deliver.destination.symbol}</span> <span>{deliver.unitsRequired}</span> <span>{deliver.unitsFulfilled}</span> </div> {/each} </td> <td>{contract.accepted}</td> <td>{contract.fulfilled}</td> <td>{contract.expirationDate.toLocaleString()}</td> <td>{contract.deadlineToAccept.toLocaleString()}</td> <td> {#if contract.accepted === false} <Button label="accept" on:buttonClicked="{accept(contract.id)}" /> {/if} </td> </tr> {/each} </tbody> </table> {/if} |