From 59e8a2b7a26294c68baeed008744f9d7948d5cc2 Mon Sep 17 00:00:00 2001 From: Aleksandr Bautin Date: Mon, 6 Nov 2023 14:02:58 +0300 Subject: [PATCH] * --- src/api.ts | 2 +- src/components/Header.vue | 3 + src/components/SiteSettings.vue | 4 +- src/main.ts | 182 +++++++++++++++++--------------- src/views/Explore.vue | 6 +- 5 files changed, 109 insertions(+), 88 deletions(-) diff --git a/src/api.ts b/src/api.ts index afa66ac..647ad30 100644 --- a/src/api.ts +++ b/src/api.ts @@ -15,7 +15,7 @@ export class Api { public readonly tonviewer_url: string; constructor() { - if (process.env.NODE_ENV === "development" && false) { + if (process.env.NODE_ENV === "development") { this.api_url = "http://localhost:5170/"; this.ton_api_url = "https://testnet.tonapi.io/v2/"; this.tonscan_url = "https://testnet.tonscan.org/"; diff --git a/src/components/Header.vue b/src/components/Header.vue index 29abb1b..a439f08 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -66,6 +66,9 @@ export default { return address.slice(0, 5) + "..." + address.slice(-4); }, }, + async mounted() { + this.$store.getters.connector.restoreConnection(); + }, }; diff --git a/src/components/SiteSettings.vue b/src/components/SiteSettings.vue index b5a8b47..abd3d04 100644 --- a/src/components/SiteSettings.vue +++ b/src/components/SiteSettings.vue @@ -175,13 +175,15 @@ export default { constructor_params: { handler: function (newVal) { this.$emit("change-constructor", newVal); + this.constructor_params.template_id = this.activeTemplateName; }, deep: true, }, saved_constructor_params: { handler: function (newVal, oldVal) { if (newVal === oldVal) return; - this.constructor_params = newVal.copy(); + // this.constructor_params.template_id = this.activeTemplateName; + // this.constructor_params = newVal.copy(); this.contacts = newVal.contacts ? Object.entries(newVal.contacts) : []; }, deep: true, diff --git a/src/main.ts b/src/main.ts index a82a311..faa8755 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,100 +1,112 @@ -import {createApp} from 'vue' -import App from './App.vue' -import router from './router' -import {createStore} from 'vuex' -import TonConnect from '@tonconnect/sdk'; -import {isWalletInfoInjected} from '@tonconnect/sdk'; -import type {WalletInfo, WalletInfoInjected, WalletInfoRemote} from '@tonconnect/sdk'; -import './assets/main.css' +import { createApp } from "vue"; +import App from "./App.vue"; +import router from "./router"; +import { createStore } from "vuex"; +import TonConnect from "@tonconnect/sdk"; +import { isWalletInfoInjected } from "@tonconnect/sdk"; +import type { + WalletInfo, + WalletInfoInjected, + WalletInfoRemote, +} from "@tonconnect/sdk"; +import "./assets/main.css"; -const app = createApp(App) +const app = createApp(App); class State { - connector: TonConnect; - walletList: WalletInfo[] = []; - initialization: Promise; + connector: TonConnect; + walletList: WalletInfo[] = []; + initialization: Promise; - constructor() { - this.connector = new TonConnect({manifestUrl: 'https://front.agorata.io/tonconnect-manifest.json'}); - this.initialization = this.initialize(); - } + constructor() { + this.connector = new TonConnect({ + manifestUrl: "https://front.agorata.io/tonconnect-manifest.json", + }); + this.initialization = this.initialize(); + } - async initialize() { - await this.connector.restoreConnection(); - this.walletList = await this.connector.getWallets(); - } + async initialize() { + await this.connector.restoreConnection(); + this.walletList = await this.connector.getWallets(); + } } const store = createStore({ - state() { - return new State() + state() { + return new State(); + }, + mutations: { + set_connector(state, connector) { + state.connector = connector; }, - mutations: { - set_connector(state, connector) { - state.connector = connector - } + }, + getters: { + is_connected(state) { + return state.connector.connected; }, - getters: { - is_connected(state) { - return state.connector.connected; - }, - address(state) { - if (state.connector.account !== null && state.connector.account.address !== undefined) { - return state.connector.account.address; - } else { - return ''; - } - } + address(state) { + if ( + state.connector.account !== null && + state.connector.account.address !== undefined + ) { + return state.connector.account.address; + } else { + return ""; + } + }, + connector(state) { + return state.connector; }, - actions: { - async connect_embedded({state}) { - const walletsList = await TonConnect.getWallets(); - let connector = state.connector; - const embeddedWallet = walletsList.find( - wallet => isWalletInfoInjected(wallet) && wallet.embedded - ) as WalletInfoInjected; - console.log(walletsList, embeddedWallet); + }, + actions: { + async connect_embedded({ state }) { + const walletsList = await TonConnect.getWallets(); + let connector = state.connector; + const embeddedWallet = walletsList.find( + (wallet) => isWalletInfoInjected(wallet) && wallet.embedded + ) as WalletInfoInjected; + console.log(walletsList, embeddedWallet); - if (embeddedWallet) { - connector.connect({jsBridgeKey: embeddedWallet.jsBridgeKey}); - } - }, - /* Connect embedded wallet if it exists, otherwise get connection url for a QR code unless we're already connected */ - async get_connection_url({state}): Promise { - await state.initialization; - await this.dispatch('connect_embedded'); - if (state.connector.connected) { - return null; - } - let walletList = this.state.walletList as WalletInfo[]; - if (walletList.length === 0) { - return null; - } - /* iterate through wallets and do try-catch */ - for (let wallet of walletList) { - try { - let wallet_r = wallet as WalletInfoRemote; - let wallet_desc = { - bridgeUrl: wallet_r.bridgeUrl, - universalLink: wallet_r.universalLink - } - let res = await state.connector.connect(wallet_desc); - if (typeof res === 'string') { - return res; - } - } catch (e) { - console.log(wallet, e) - } - } - return null; - }, - async disconnect({state}) { - await state.connector.disconnect(); + if (embeddedWallet) { + connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }); + } + }, + /* Connect embedded wallet if it exists, otherwise get connection url for a QR code unless we're already connected */ + async get_connection_url({ state }): Promise { + await state.initialization; + await this.dispatch("connect_embedded"); + if (state.connector.connected) { + return null; + } + let walletList = this.state.walletList as WalletInfo[]; + if (walletList.length === 0) { + return null; + } + /* iterate through wallets and do try-catch */ + for (let wallet of walletList) { + try { + let wallet_r = wallet as WalletInfoRemote; + let wallet_desc = { + bridgeUrl: wallet_r.bridgeUrl, + universalLink: wallet_r.universalLink, + }; + let res = await state.connector.connect(wallet_desc); + if (typeof res === "string") { + return res; + } + } catch (e) { + console.log(wallet, e); } - } -}) + } + return null; + }, + async disconnect({ state }) { + await state.connector.disconnect(); + }, + }, +}); -app.use(router) -app.use(store) +app.use(router); +app.use(store); -app.mount('#app') +app.mount("#app"); diff --git a/src/views/Explore.vue b/src/views/Explore.vue index c7459a9..49f044e 100644 --- a/src/views/Explore.vue +++ b/src/views/Explore.vue @@ -94,11 +94,12 @@ @save-constructor="saveSiteConstr()" @select-template="selectTemplate" @change="site_rec = $event" - @change-constructor="constructor_params = $event" :template-id="constructor_params.template_id" :site-changed="siteChanged" :signing-site="signingSite" + @change-constructor="changeConstructor" /> +
This domain is not owned. @@ -331,6 +332,9 @@ export default { useMyWallet() { this.wallet_rec = this.$store.getters.address; }, + changeConstructor(evt) { + this.constructor_params = evt; + }, }, watch: { records: function (val) {