Browse Source

Integrating with the api

vue
Lev 2 years ago
parent
commit
6b92f1273e
  1. 19
      .idea/workspace.xml
  2. 4
      src/api.ts
  3. 2
      src/components/DomainResult.vue
  4. 1
      src/main.ts
  5. 39
      src/result.ts
  6. 14
      src/views/Checkout.vue

19
.idea/workspace.xml

@ -2,10 +2,11 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="ddb8afd5-d3ba-47b1-b6d0-227403f1abf7" name="Changes" comment="Checkout">
<change afterPath="$PROJECT_DIR$/src/components/Socket.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/api.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/DomainResult.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/DomainResult.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/result.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/result.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/views/Checkout.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/Checkout.vue" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -88,7 +89,10 @@
<workItem from="1672337938860" duration="148000" />
<workItem from="1672483245701" duration="3321000" />
<workItem from="1672753446569" duration="4197000" />
<workItem from="1672782388693" duration="23465000" />
<workItem from="1672782388693" duration="27397000" />
<workItem from="1673123515646" duration="82000" />
<workItem from="1673195751389" duration="2458000" />
<workItem from="1673683299593" duration="12019000" />
</task>
<task id="LOCAL-00001" summary="Wrote the landing">
<created>1670844191163</created>
@ -223,7 +227,14 @@
<option name="project" value="LOCAL" />
<updated>1672868732315</updated>
</task>
<option name="localTasksCounter" value="20" />
<task id="LOCAL-00020" summary="Checkout">
<created>1672913681110</created>
<option name="number" value="00020" />
<option name="presentableId" value="LOCAL-00020" />
<option name="project" value="LOCAL" />
<updated>1672913681110</updated>
</task>
<option name="localTasksCounter" value="21" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">

4
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;
}

2
src/components/DomainResult.vue

@ -3,7 +3,7 @@
<RotateSquare2 style="width: 5rem; height: 5rem; margin-top: 3rem;"/>
</div>
<GetDomainBtn v-else-if="result.canBuy() && result.condition_fullfilled !== false"
:domain="domain" :price="result.auction_price"
:domain="domain" :price="result.buy_price"
:collection_required="result.collection_required"
@click="buy()"/>
<!-- todo: differentiate between auction and buy -->

1
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});

39
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 {

14
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() {

Loading…
Cancel
Save