Aleksandr Bautin 1 year ago
parent
commit
59e8a2b7a2
No known key found for this signature in database
GPG Key ID: 9B3364A12DFE9211
  1. 2
      src/api.ts
  2. 3
      src/components/Header.vue
  3. 4
      src/components/SiteSettings.vue
  4. 182
      src/main.ts
  5. 6
      src/views/Explore.vue

2
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/";

3
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();
},
};
</script>

4
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,

182
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<void>;
connector: TonConnect;
walletList: WalletInfo[] = [];
initialization: Promise<void>;
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<string | null> {
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<string | null> {
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");

6
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"
/>
<!-- @change-constructor="changeConstructor" -->
</div>
<div v-else>
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) {

Loading…
Cancel
Save