From 6b92f1273e47d29441ebb481e25bf7dfe8dd4804 Mon Sep 17 00:00:00 2001 From: ennucore Date: Mon, 16 Jan 2023 10:14:18 +0100 Subject: [PATCH] Integrating with the api --- .idea/workspace.xml | 19 ++++++++++++---- src/api.ts | 4 ++-- src/components/DomainResult.vue | 2 +- src/main.ts | 1 + src/result.ts | 39 +++++++++++++++++++++++---------- src/views/Checkout.vue | 14 +++++++----- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 462d1e4..96ee943 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,11 @@ - + + + - diff --git a/src/api.ts b/src/api.ts index 143fd5c..e997b80 100644 --- a/src/api.ts +++ b/src/api.ts @@ -11,7 +11,7 @@ export class Api { constructor() { if (process.env.NODE_ENV === 'development') { - this.api_url = 'http://localhost:5000/'; + this.api_url = 'http://localhost:5170/'; } else { this.api_url = 'https://api.agorata.io/'; } @@ -21,5 +21,5 @@ export class Api { export const config = new Api(); export async function call_api(url: string) { - return (await axios.get(config.api_url + url, {withCredentials: true})).data; + return (await axios.get(config.api_url + url)).data; } diff --git a/src/components/DomainResult.vue b/src/components/DomainResult.vue index 591069e..9b9c0c1 100644 --- a/src/components/DomainResult.vue +++ b/src/components/DomainResult.vue @@ -3,7 +3,7 @@ diff --git a/src/main.ts b/src/main.ts index 80d553b..f276049 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,6 +53,7 @@ const store = createStore({ const embeddedWallet = walletsList.find( wallet => isWalletInfoInjected(wallet) && wallet.embedded ) as WalletInfoInjected; + console.log(walletsList, embeddedWallet); if (embeddedWallet) { connector.connect({jsBridgeKey: embeddedWallet.jsBridgeKey}); diff --git a/src/result.ts b/src/result.ts index 9605676..4bc9a0b 100644 --- a/src/result.ts +++ b/src/result.ts @@ -2,7 +2,8 @@ import {Zone} from "@/zone"; import {Collection} from "@/collection"; -import {parse_zone, Message} from "@/utils"; +import type {Message} from "@/utils"; +import {call_api} from "@/api"; let ex_collection = () => new Collection("example.ton", "Example collection"); @@ -14,8 +15,9 @@ export class Result { collection_required: Collection | null; condition_fulfilled: boolean | null = null; buy_msg: Message | null = null; + content_msg: Message | null = null; - constructor(domain: string, buy_price?: number, auction_price?: number, owner?: string, collection_required: Collection | null = null, condition_fulfilled: boolean | null = null, buy_msg: Message | null = null) { + constructor(domain: string, buy_price?: number, auction_price?: number, owner?: string, collection_required: Collection | null = null, condition_fulfilled: boolean | null = null, buy_msg: Message | null = null, content_msg: Message | null = null) { this.domain = domain; this.buy_price = buy_price; this.auction_price = auction_price; @@ -23,6 +25,20 @@ export class Result { this.collection_required = collection_required; this.condition_fulfilled = condition_fulfilled; this.buy_msg = buy_msg; + this.content_msg = content_msg; + } + + static fromBackend(data: any): Result { + let domain = data.domain; + let buy_price = data.buy_price; + let auction_price = data.auction_price; + let owner = data.owner; + let collection_required = data.collection_required; + let condition_fulfilled = data.condition_fulfilled; + let buy_msg = data.buy_msg; + let content_msg = data.content_msg; + + return new Result(domain, buy_price, auction_price, owner, collection_required, condition_fulfilled, buy_msg, content_msg); } getRouteParams(): any { @@ -51,19 +67,19 @@ const sleep = (milliseconds: number) => { } export async function get_search_results(query: string) { - // return await call_api('find/' + query); - await sleep(200); + return Result.fromBackend(await call_api('find/' + query)); + /*await sleep(200); return [ new Result(query + '.ton', 5, 3), new Result(query + '.ton', 1), new Result(query + '.ton', undefined, 2), new Result(query + '.ton', undefined, undefined, '123') - ]; + ];*/ } export async function get_domain_result(domain: string, address?: string) { - // return await call_api('get/' + domain); - await sleep(100); + return Result.fromBackend(await call_api('get/' + domain)); + /*await sleep(100); if (domain === 'test.ton') { return new Result(domain); } @@ -82,16 +98,17 @@ export async function get_domain_result(domain: string, address?: string) { return new Result(domain, 5, 3, undefined, exc); } } - return new Result(domain, 5, 3); + return new Result(domain, 5, 3);*/ } export async function get_zones() { - // return await call_api('zones'); - await sleep(10); + let zones_back = await call_api('zones'); + return zones_back.map((zone: any) => new Zone(zone.zone, zone.price_buy_1, zone.price_buy_2, zone.collection_required, zone.price_auction_1, zone.price_auction_2, zone.min_length, zone.length_1, zone.length_2, zone.address)); + /*await sleep(10); return [ new Zone("example.ton", 3, 5, ex_collection()), new Zone("agorata.ton", 3, 5), - new Zone("testtesttest.ton", 1, 1, ex_collection())]; + new Zone("testtesttest.ton", 1, 1, ex_collection())];*/ } export class TonLink { diff --git a/src/views/Checkout.vue b/src/views/Checkout.vue index 5dc66c0..99f9229 100644 --- a/src/views/Checkout.vue +++ b/src/views/Checkout.vue @@ -49,24 +49,26 @@ export default { this.result = await get_domain_result(this.domain + '.' + this.zone); this.ton_link = await get_ton_link(this.result); }, - async sign_transaction() - { + async sign_transaction() { await this.get_result(); let d = new Date(); - let validness = parseInt((d.getTime() / 100).toFixed(0)) + 3600; + let validness = parseInt((d.getTime() / 1000).toFixed(0)) + 360000; const transaction = { validUntil: validness, messages: [ - this.result.buy_msg + Object.assign({}, this.result.content_msg), + Object.assign({}, this.result.buy_msg) ] } - await this.$store.state.connector.sendTransaction(transaction); + console.log("Signing the transaction", transaction); + const result = await this.$store.state.connector.sendTransaction(transaction); + console.log(result); this.$router.push({name: 'Explore', params: {domain: this.domain + '.' + this.zone}}); } }, mounted() { - this.get_result() + this.sign_transaction() }, computed: { loaded() {