From 22f8343fca507d50a528f8c0f55f6c5e1faf1b95 Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 14:19:21 +0200 Subject: [PATCH 01/16] Add activeProfile Store & added it to base component --- package.json | 1 + src/App.svelte | 12 +- src/elements/base/Base.wc.svelte | 20 ++-- src/global.d.ts | 20 ++-- src/stores/activeProfile.ts | 49 ++++++++ src/stores/balance.ts | 83 ------------- src/stores/baseConfig.ts | 194 ------------------------------- src/utils/getGrid.ts | 18 ++- yarn.lock | 5 + 9 files changed, 92 insertions(+), 310 deletions(-) create mode 100644 src/stores/activeProfile.ts delete mode 100644 src/stores/balance.ts delete mode 100644 src/stores/baseConfig.ts diff --git a/package.json b/package.json index aade0b4c..64266f36 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "rollup-plugin-node-builtins": "^2.1.2", "serve": "^13.0.2", "sirv-cli": "^1.0.0", + "tf-profile-manager": "^1.0.0", "ts-rmb-http-client": "1.0.6", "uuid": "^8.3.2", "yarn": "^1.22.17" diff --git a/src/App.svelte b/src/App.svelte index ca3b33bd..cd3ec0e6 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,4 +1,14 @@ + + diff --git a/src/elements/base/Base.wc.svelte b/src/elements/base/Base.wc.svelte index 8888f4b2..6e5b6d3b 100644 --- a/src/elements/base/Base.wc.svelte +++ b/src/elements/base/Base.wc.svelte @@ -1,23 +1,20 @@ + diff --git a/src/global.d.ts b/src/global.d.ts index 96b27087..0df2911a 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,27 +1,25 @@ /// -import * as client from "ts-rmb-http-client"; -import * as grid3_client from "grid3_client"; -import * as buffer from "buffer"; -import * as bip39 from "bip39"; +import * as client from 'ts-rmb-http-client'; +import * as grid3_client from 'grid3_client'; +import * as buffer from 'buffer'; +import * as bip39 from 'bip39'; // stores -import baseConfigStore from "./stores/baseConfig"; -import deploymentStore from "./stores/deploymentStore"; -import notificationStore from "./stores/notifications"; -import currentDeploymentStore from "./stores/currentDeployment"; -import balanceStore from "./stores/balance"; +import deploymentStore from './stores/deploymentStore'; +import notificationStore from './stores/notifications'; +import currentDeploymentStore from './stores/currentDeployment'; +import activeProfileStore from './stores/activeProfile'; interface AppConfigs { client: typeof client; grid3_client: typeof grid3_client; - baseConfig: typeof baseConfigStore; deploymentStore: typeof deploymentStore; notificationStore: typeof notificationStore; currentDeploymentStore: typeof currentDeploymentStore; - balanceStore: typeof balanceStore; buffer: typeof buffer; bip39: typeof bip39; + activeProfileStore: typeof activeProfileStore; } declare global { diff --git a/src/stores/activeProfile.ts b/src/stores/activeProfile.ts new file mode 100644 index 00000000..e8538a4f --- /dev/null +++ b/src/stores/activeProfile.ts @@ -0,0 +1,49 @@ +import ProfileManager, { Profile, Listener } from 'tf-profile-manager'; +import { writable, Writable } from 'svelte/store'; +import getGrid from '../utils/getGrid'; + +async function _createActiveProfileStore(cb: Listener) { + if (await ProfileManager.isInstalled) { + ProfileManager.subscribe(cb); + } +} + +function _createBalanceStore(profile: Profile) { + const balanceStore = writable<{ + balance: number; + locked: number; + }>(); + + getGrid(profile, (_) => _).then((grid) => { + ProfileManager.subscribeToBalance(grid, (balance) => { + balanceStore.set(balance); + }); + }); + + return balanceStore; +} + +export interface ActiveProfile extends Profile { + balance: Writable<{ + balance: number; + locked: number; + }>; +} + +function createActiveProfileStore() { + const { subscribe, set } = writable(null); + + _createActiveProfileStore((profile) => { + if (!profile) return set(null); + set({ + ...profile, + balance: _createBalanceStore(profile), + }); + }); + + return { + subscribe, + }; +} + +export default createActiveProfileStore(); diff --git a/src/stores/balance.ts b/src/stores/balance.ts deleted file mode 100644 index b6c6733c..00000000 --- a/src/stores/balance.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { get, writable } from "svelte/store"; -import getBalance from "../utils/getBalance"; - -interface IStore { - loading: boolean; - balance: number | number; - locked: number | number; -} - -function createBalanceStore() { - const store = writable({ - loading: false, - balance: null, - locked: null, - }); - const { subscribe, update } = store; - - const fullStore = { - subscribe, - - getBalance() { - return get(store).balance; - }, - - setBalance(value: number) { - return update((s) => { - s.balance = value; - return s; - }); - }, - - setLockedBalance(value: number) { - return update((s) => { - s.locked = value; - return s; - }); - }, - - setLoading(value: boolean) { - return update((s) => { - s.loading = value; - return s; - }); - }, - - updateBalance(times: number = 0) { - const profile = window.configs.baseConfig.getActiveProfile(); - if (!profile) return; - - fullStore.setLoading(true); - - getBalance(profile) - .then((balance) => { - fullStore.setBalance(balance.free); - fullStore.setLockedBalance(balance.feeFrozen); - }) - .catch((err) => { - console.log("Balance Error", err); - if (times < 3) fullStore.updateBalance(times + 1); - }) - .finally(() => { - fullStore.setLoading(false); - }); - }, - }; - - requestAnimationFrame(() => { - let _interval: any; - - window.configs.baseConfig.subscribe(({ activeProfile }) => { - if (_interval) clearInterval(_interval); - _interval = null; - if (activeProfile === null) return; - - fullStore.updateBalance(); - setInterval(() => fullStore.updateBalance(), 60 * 1000); - }); - }); - - return fullStore; -} - -export default createBalanceStore(); diff --git a/src/stores/baseConfig.ts b/src/stores/baseConfig.ts deleted file mode 100644 index 77f49abd..00000000 --- a/src/stores/baseConfig.ts +++ /dev/null @@ -1,194 +0,0 @@ -import { get, writable } from "svelte/store"; -import { enc } from "crypto-js"; -import md5 from "crypto-js/md5"; -import { encrypt, decrypt } from "crypto-js/aes"; -import { v4 } from "uuid"; -import type { IProfile } from "../types/Profile"; -import getGrid from "../utils/getGrid"; - -const PREFIX = "v2."; -const createProfile = ( - name = "", - m = "", - n = process.env.NETWORK, - key = "" -) => { - const result = { - id: v4(), - name, - mnemonics: m, - storeSecret: "", - networkEnv: n, - sshKey: key, - }; - - return result; -}; - -function createBaseConfig() { - const store = writable({ - profiles: [createProfile("Profile1")], - activeProfile: null, - twinId: null, - address: null, - storeSecret: null, - }); - - function hashPassword(password: string) { - return PREFIX + md5(password).toString(); - } - - function getEncryptedStore(password: string) { - const data = JSON.stringify(get(store)); - return encrypt(data, password).toString(); - } - - const { subscribe, set, update } = store; - - const fullStore = { - subscribe, - set, - update, - updateMnemonics(idx: number, e: InputEvent) { - return update((value) => { - value.profiles[idx].mnemonics = (e.target as any).value; - return value; - }); - }, - updateNetworkEnv(idx: number, e: Event) { - return update((value) => { - value.profiles[idx].networkEnv = (e.target as any).selectedIndex === 0 ? "test" : "dev"; // prettier-ignore - return value; - }); - }, - updateName(idx: number, e: InputEvent) { - return update((value) => { - value.profiles[idx].name = (e.target as any).value; - return value; - }); - }, - updateSshKey(idx: number, e: InputEvent) { - return update((value) => { - value.profiles[idx].sshKey = (e.target as any).value; - return value; - }); - }, - addProfile() { - let _idx: string; - update((value) => { - _idx = (value.profiles.push(createProfile()) - 1).toString(); - return value; - }); - return _idx; - }, - deleteProfile(idx: number, current: string) { - let _idx: string; - update((value) => { - if (value.profiles[idx].id === value.activeProfile) { - value.activeProfile = null; - } - value.profiles.splice(idx, 1); - if (current === idx.toString()) { - _idx = (idx - 1).toString(); - } - return value; - }); - return _idx ? _idx : current; - }, - - create(password: string) { - const hash = hashPassword(password); - - if (localStorage.getItem(hash) !== null) { - return "Password already exists."; - } - - localStorage.setItem(hash, getEncryptedStore(password)); - sessionStorage.setItem("session_password", password); - }, - - load(password: string) { - const hash = hashPassword(password); - const data = localStorage.getItem(hash); - - if (data === null) { - return "Password is not correct."; - } - - try { - set(JSON.parse(decrypt(data, password).toString(enc.Utf8))); - sessionStorage.setItem("session_password", password); - update((value) => { - value.storeSecret = password; - return value; - }); - - if (get(store).activeProfile) { - fullStore._loadActiveProfileInfo(); - } - } catch { - return "Incorrect data."; - } - }, - - _loadActiveProfileInfo() { - getGrid(fullStore.getActiveProfile(), (grid) => { - grid.twins - .get_my_twin_id() - .then((twin) => { - update((value) => { - value.twinId = twin; - value.address = grid.twins.client.client.address; - return value; - }); - }) - .catch((err) => { - console.log("Error", err); - }); - }); - }, - - save(password: string) { - const hash = hashPassword(password); - - if (localStorage.getItem(hash) === null) { - return "Password wasn't found."; - } - - localStorage.setItem(hash, getEncryptedStore(password)); // prettier-ignore - window.configs.notificationStore.notify("success", "Saved!"); - }, - - setActiveProfile(id: string, password: string) { - update((value) => { - value.activeProfile = id; - value.storeSecret = id === null ? null : password; - value.twinId = null; - value.address = null; - return value; - }); - requestAnimationFrame(() => { - fullStore.save(password); - if (id !== null) { - setTimeout(() => { - fullStore._loadActiveProfileInfo(); - }, 1000); - } - }); - }, - - getActiveProfile(): IProfile | null { - const data = get(store); - if (data.activeProfile === null) return null; - const idx = data.profiles.findIndex((p) => p.id === data.activeProfile); - const profile = data.profiles[idx] as IProfile; - profile.storeSecret = data.storeSecret; - profile.networkEnv = process.env.NETWORK; - return profile; - }, - }; - - return fullStore; -} - -export default createBaseConfig(); diff --git a/src/utils/getGrid.ts b/src/utils/getGrid.ts index a46abb94..67c3ab7f 100644 --- a/src/utils/getGrid.ts +++ b/src/utils/getGrid.ts @@ -1,18 +1,16 @@ -import type { IProfile } from "../types/Profile"; -import type { GridClient } from "grid3_client"; +import type { Profile } from 'tf-profile-manager'; +import type { GridClient, NetworkEnv } from 'grid3_client'; export default async function getGrid( - profile: IProfile, - cb: (grid: GridClient) => T, - disconnect: boolean = true, - solutionType?: string + profile: Profile, + cb: (grid: GridClient) => T ): Promise { - const { networkEnv, mnemonics, storeSecret } = profile; + const { network, mnemonics, secret } = profile; const grid = new window.configs.grid3_client.GridClient( - networkEnv as any, + network as NetworkEnv, mnemonics, - storeSecret, - new window.configs.client.HTTPMessageBusClient(0, "", "", ""), + secret, + new window.configs.client.HTTPMessageBusClient(0, '', '', ''), undefined, window.configs.grid3_client.BackendStorageType.tfkvstore ); diff --git a/yarn.lock b/yarn.lock index c5d63ca7..3be0ed3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8098,6 +8098,11 @@ terser@^5.0.0, terser@^5.14.1: commander "^2.20.0" source-map-support "~0.5.20" +tf-profile-manager@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/tf-profile-manager/-/tf-profile-manager-1.0.0.tgz#dc35184787f75803921f8e3dfaec582984e9e04a" + integrity sha512-NgvZnFxiUUx06AkQH6UAq9meDd1ypFmkqdnjsPV0TAMcJuxtf6uKo002aLFbxf1u7XrxV/qzYMWpXw+akBonPQ== + tfgrid-api-client@1.16.4: version "1.16.4" resolved "https://registry.yarnpkg.com/tfgrid-api-client/-/tfgrid-api-client-1.16.4.tgz#04301a465ff148083884cd64bd5bcb4696a9aa04" From bf5ec1a9643e841ca3d4c688bc231297dfb5d4b3 Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 14:51:44 +0200 Subject: [PATCH 02/16] Add ProfileManager instead of profiles element --- src/App.svelte | 94 ++- .../ProfileManager/ProfileManager.wc.svelte | 41 ++ src/elements/ProfileManager/index.ts | 1 + src/elements/profiles/Profiles.wc.svelte | 555 ------------------ src/elements/profiles/index.ts | 1 - 5 files changed, 84 insertions(+), 608 deletions(-) create mode 100644 src/elements/ProfileManager/ProfileManager.wc.svelte create mode 100644 src/elements/ProfileManager/index.ts delete mode 100644 src/elements/profiles/Profiles.wc.svelte delete mode 100644 src/elements/profiles/index.ts diff --git a/src/App.svelte b/src/App.svelte index cd3ec0e6..c66de846 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,61 +1,51 @@ - - - - {#if configured} -
- - - -
- {/if} - - -

- Please visit - the manual - - to get started. -

-
- - {#if configured} - { - selectedIdx = configs.deleteProfile(detail, selectedIdx); - }} - on:select={(p) => { - fields.forEach((_, i) => (fields[i].error = null)); - selectedIdx = p.detail; - }} - on:init={() => (selectedIdx = "0")} - /> - -
- -
- - {#if activeProfile} -
-
- { - fields[0].error = validateProfileName(activeProfile.name); - }} - /> - - - - {#if activeProfileId === activeProfile?.id} - - - {/if} -
-
- -
-
- -
-
-
- - {#if activeProfileId === activeProfile?.id} -
-
-

- Scan code using Threefold connect to send tokens -

- {#if $configs.twinId} - - {:else} -

Loading scan code...

- {/if} -
- {/if} -
- {/if} - {:else} - - -
- - - {#if message} - - {/if} - -
- -
- - {/if} -
- - - - diff --git a/src/elements/profiles/index.ts b/src/elements/profiles/index.ts deleted file mode 100644 index 76550a01..00000000 --- a/src/elements/profiles/index.ts +++ /dev/null @@ -1 +0,0 @@ -import "./Profiles.wc.svelte"; From 4dafe1ebd7bc2ff3506790703755fe0edc795ea2 Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 15:29:05 +0200 Subject: [PATCH 03/16] Apply fix to fullvm --- src/App.svelte | 4 +- src/components/LogsInfo.svelte | 2 +- src/components/SelectNodeId.svelte | 177 +++++++++--------- src/components/SelectProfile.svelte | 63 ------- .../ProfileManager/ProfileManager.wc.svelte | 2 + src/elements/fullvm/Fullvm.wc.svelte | 126 ++++++------- src/stores/activeProfile.ts | 3 + src/types/Profile.ts | 8 - src/utils/deploy.ts | 23 +-- src/utils/deployVM.ts | 24 +-- src/utils/fetchCountries.ts | 23 ++- src/utils/fetchFarms.ts | 12 +- src/utils/findNodes.ts | 38 ++-- src/utils/getGrid.ts | 2 +- src/utils/gqlApi.ts | 19 +- src/utils/hasEnoughBalance.ts | 8 +- 16 files changed, 233 insertions(+), 301 deletions(-) delete mode 100644 src/components/SelectProfile.svelte delete mode 100644 src/types/Profile.ts diff --git a/src/App.svelte b/src/App.svelte index c66de846..4a3e0fc2 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,7 +2,7 @@ import Base from './elements/base/Base.wc.svelte'; import ProfileManager from './elements/ProfileManager/ProfileManager.wc.svelte'; - // import Fullvm from "./elements/fullvm/Fullvm.wc.svelte"; + import Fullvm from './elements/fullvm/Fullvm.wc.svelte'; // import Vm from "./elements/vm/Vm.wc.svelte"; // import Kubernetes from "./elements/kubernetes/Kubernetes.wc.svelte"; // import Caprover from "./elements/caprover/Caprover.wc.svelte"; @@ -45,6 +45,8 @@ + + diff --git a/src/elements/ProfileManager/ProfileManager.wc.svelte b/src/elements/ProfileManager/ProfileManager.wc.svelte index 8a2763f9..51222b0d 100644 --- a/src/elements/ProfileManager/ProfileManager.wc.svelte +++ b/src/elements/ProfileManager/ProfileManager.wc.svelte @@ -1,3 +1,5 @@ + + - { - profile = detail; - if (detail) { - data.envs[0] = new Env(undefined, "SSH_KEY", detail?.sshKey); - } - }} -/> -

Deploy a Full Virtual Machine

@@ -219,8 +210,8 @@


- {#if loading || (logs !== null && logs.type === "Fullvm")} - + {#if loading || (logs !== null && logs.type === 'Fullvm')} + {:else if !profile} {:else if success} @@ -230,11 +221,11 @@ deployed={true} /> {:else if failed} - + {:else} - {#if active === "config"} + {#if active === 'config'} - {#if flistSelectValue === "other"} + {#if flistSelectValue === 'other'} { @@ -268,11 +259,11 @@ {/if} @@ -301,11 +292,10 @@ bind:data={data.nodeId} filters={data.selection.filters} bind:status - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> - {:else if active === "env"} + {:else if active === 'env'} (data.envs = [...data.envs, new Env()])} />
{#each data.envs as env, index (env.id)} @@ -321,7 +311,7 @@
{/each}
- {:else if active === "disks"} + {:else if active === 'disks'} (data.disks = [...data.disks, new Disk()])} />
{#each data.disks as disk, index (disk.id)} @@ -333,7 +323,7 @@ (data.disks = data.disks.filter((_, i) => index !== i))} /> {#each disk.diskFields as field (field.symbol)} - {#if field.symbol === "mountpoint"} + {#if field.symbol === 'mountpoint'} - {:else if field.symbol === "name"} + {:else if field.symbol === 'name'} - @import url("https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"); - @import "../../assets/global.scss"; + @import url('https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css'); + @import '../../assets/global.scss'; diff --git a/src/stores/activeProfile.ts b/src/stores/activeProfile.ts index e8538a4f..38033e24 100644 --- a/src/stores/activeProfile.ts +++ b/src/stores/activeProfile.ts @@ -1,6 +1,7 @@ import ProfileManager, { Profile, Listener } from 'tf-profile-manager'; import { writable, Writable } from 'svelte/store'; import getGrid from '../utils/getGrid'; +import type { NetworkEnv } from 'grid3_client'; async function _createActiveProfileStore(cb: Listener) { if (await ProfileManager.isInstalled) { @@ -24,6 +25,7 @@ function _createBalanceStore(profile: Profile) { } export interface ActiveProfile extends Profile { + network: NetworkEnv; balance: Writable<{ balance: number; locked: number; @@ -38,6 +40,7 @@ function createActiveProfileStore() { set({ ...profile, balance: _createBalanceStore(profile), + network: profile.network as unknown as NetworkEnv, }); }); diff --git a/src/types/Profile.ts b/src/types/Profile.ts deleted file mode 100644 index 6402bac1..00000000 --- a/src/types/Profile.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface IProfile { - id: string; - name: string; - mnemonics: string; - storeSecret: string; - networkEnv: string; - sshKey: string; -} diff --git a/src/utils/deploy.ts b/src/utils/deploy.ts index 6ebfd03f..56817c47 100644 --- a/src/utils/deploy.ts +++ b/src/utils/deploy.ts @@ -1,23 +1,18 @@ -import type { GridClient } from "grid3_client"; -import type { IStore } from "../stores/currentDeployment"; -import type { IProfile } from "../types/Profile"; -import getGrid from "./getGrid"; +import type { GridClient } from 'grid3_client'; +import type { ActiveProfile } from '../stores/activeProfile'; +import type { IStore } from '../stores/currentDeployment'; +import getGrid from './getGrid'; export default function deploy( - profile: IProfile, - type: IStore["type"], + profile: ActiveProfile, + type: IStore['type'], name: string, deployer: (grid: GridClient) => Promise ) { window.configs.currentDeploymentStore.deploy(type, name); return getGrid(profile, (grid) => { - return deployer(grid) - .then((res) => { - window.configs.balanceStore.updateBalance(); - return res; - }) - .finally(() => { - window.configs.currentDeploymentStore.clear(); - }); + return deployer(grid).finally(() => { + window.configs.currentDeploymentStore.clear(); + }); }); } diff --git a/src/utils/deployVM.ts b/src/utils/deployVM.ts index c79d0e5e..3595e564 100644 --- a/src/utils/deployVM.ts +++ b/src/utils/deployVM.ts @@ -1,16 +1,16 @@ -import type { default as VM, Disk, Env } from "../types/vm"; -import createNetwork from "./createNetwork"; +import type { default as VM, Disk, Env } from '../types/vm'; +import createNetwork from './createNetwork'; -import type { IProfile } from "../types/Profile"; -import deploy from "./deploy"; -import type { IStore } from "../stores/currentDeployment"; -import checkVMExist from "./prepareDeployment"; -import { Network } from "../types/kubernetes"; +import deploy from './deploy'; +import type { IStore } from '../stores/currentDeployment'; +import checkVMExist from './prepareDeployment'; +import { Network } from '../types/kubernetes'; +import type { ActiveProfile } from '../stores/activeProfile'; export default async function deployVM( data: VM, - profile: IProfile, - type: IStore["type"] + profile: ActiveProfile, + type: IStore['type'] ) { const { MachineModel, MachinesModel } = window.configs.grid3_client; const { envs, disks, rootFs, ...base } = data; @@ -36,14 +36,14 @@ export default async function deployVM( vms.network = createNetwork(new Network()); vms.machines = [vm]; const metadate = { - type: "vm", + type: 'vm', name: name, - projectName: type == "VM" ? "" : type, + projectName: type == 'VM' ? '' : type, }; vms.metadata = JSON.stringify(metadate); return deploy(profile, type, name, async (grid) => { - if (type != "VM") await checkVMExist(grid, type.toLocaleLowerCase(), name); + if (type != 'VM') await checkVMExist(grid, type.toLocaleLowerCase(), name); return grid.machines .deploy(vms) .then(() => grid.machines.getObj(name)) diff --git a/src/utils/fetchCountries.ts b/src/utils/fetchCountries.ts index 24b8281c..58be72df 100644 --- a/src/utils/fetchCountries.ts +++ b/src/utils/fetchCountries.ts @@ -1,11 +1,14 @@ -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from '../stores/activeProfile'; -export async function fetchCountries(profile: IProfile) : Promise { - const { networkEnv } = profile; - return fetch(`https://gridproxy.${networkEnv}.grid.tf/stats?status=up`, { - method: "GET", - }) - .then(response => response.json()) - .then(response => response["nodesDistribution"]) - .catch((err) => {console.log(err) ; return err}); - } +export async function fetchCountries(profile: ActiveProfile): Promise { + const { network } = profile; + return fetch(`https://gridproxy.${network}.grid.tf/stats?status=up`, { + method: 'GET', + }) + .then((response) => response.json()) + .then((response) => response['nodesDistribution']) + .catch((err) => { + console.log(err); + return err; + }); +} diff --git a/src/utils/fetchFarms.ts b/src/utils/fetchFarms.ts index 260fd010..95c61b43 100644 --- a/src/utils/fetchFarms.ts +++ b/src/utils/fetchFarms.ts @@ -1,8 +1,8 @@ import type { FilterOptions } from "grid3_client"; -import type { IProfile } from "../types/Profile"; import gqlApi from "./gqlApi"; import { getBlockedFarmsIDs } from "./findNodes"; import paginatedFetcher from "./paginatedFetcher"; +import type { ActiveProfile } from "../stores/activeProfile"; const queryCount = ` query GetLimits { @@ -40,7 +40,7 @@ interface IQueryData { } export default function fetchFarms( - profile: IProfile, + profile: ActiveProfile, filters: FilterOptions, exclusiveFor: string ) { @@ -69,7 +69,7 @@ export default function fetchFarms( }); } -export async function getOnlineFarms(profile, farms, exclusiveFor, publicIp) { +export async function getOnlineFarms(profile: ActiveProfile, farms, exclusiveFor, publicIp) { let blockedFarms = []; let onlineFarmsSet = new Set(); let onlineFarmsArr = []; @@ -78,13 +78,13 @@ export async function getOnlineFarms(profile, farms, exclusiveFor, publicIp) { // no need for exclusive for if we have an ip blockedFarms = await getBlockedFarmsIDs( exclusiveFor, - `https://gridproxy.${profile.networkEnv}.grid.tf`, - `https://graphql.${profile.networkEnv}.grid.tf/graphql` + `https://gridproxy.${profile.network}.grid.tf`, + `https://graphql.${profile.network}.grid.tf/graphql` ); } const upNodes = await paginatedFetcher( - `https://gridproxy.${profile.networkEnv}.grid.tf/nodes?&status=up`, + `https://gridproxy.${profile.network}.grid.tf/nodes?&status=up`, 0, 50 ); diff --git a/src/utils/findNodes.ts b/src/utils/findNodes.ts index 25244ad8..82c8840f 100644 --- a/src/utils/findNodes.ts +++ b/src/utils/findNodes.ts @@ -1,28 +1,32 @@ -import type { ISelectOption } from "../types"; -import type { IProfile } from "../types/Profile"; -import type { FilterOptions } from "grid3_client"; +import type { ISelectOption } from '../types'; +import type { FilterOptions } from 'grid3_client'; +import type { ActiveProfile } from '../stores/activeProfile'; export default function findNodes( filters: FilterOptions, - profile: IProfile, - exclusiveFor = "" + profile: ActiveProfile, + exclusiveFor = '' ): Promise { return new Promise(async (res) => { - const { networkEnv } = profile; + const { network } = profile; const grid = new window.configs.grid3_client.GridClient( - "" as any, - "", - "", + '' as any, + '', + '', null ); - const { graphql, rmbProxy } = grid.getDefaultUrls(networkEnv as any); - const nodes = new window.configs.grid3_client.Nodes(graphql, rmbProxy, grid.rmbClient); + const { graphql, rmbProxy } = grid.getDefaultUrls(network); + const nodes = new window.configs.grid3_client.Nodes( + graphql, + rmbProxy, + grid.rmbClient + ); try { let avilableNodes = await nodes.filterNodes(filters); - if (!filters.publicIPs && exclusiveFor != "") { + if (!filters.publicIPs && exclusiveFor != '') { const blockedNodes = await getBlockedNodesIDs( exclusiveFor, rmbProxy, @@ -43,7 +47,7 @@ export default function findNodes( }); avilableNodes = exclude(blockedNodes, avilableNodes); } catch (err) { - console.log("End of the pages."); + console.log('End of the pages.'); break; } } @@ -57,7 +61,7 @@ export default function findNodes( }); res(resNodes); } catch (err) { - console.log("Error findNodes", err); + console.log('Error findNodes', err); res([]); } }); @@ -79,7 +83,7 @@ async function getBlockedNodesIDs( ); // get all the nodeIds of all the farms - let farmsIDs = `[${blockedFarmsIDs.join(", ")}]`; + let farmsIDs = `[${blockedFarmsIDs.join(', ')}]`; const res = await gqlClient.query( `query MyQuery { nodes(where: {farmID_in: ${farmsIDs}}) { @@ -87,7 +91,7 @@ async function getBlockedNodesIDs( } }` ); - let farmNodesIDs = [...res.data["nodes"]]; + let farmNodesIDs = [...res.data['nodes']]; return farmNodesIDs; } @@ -119,7 +123,7 @@ export async function getBlockedFarmsIDs( let farmIds = new Set(); for (let nodeId of nodeIds) { const res = await fetch(`${rmbProxy}/nodes/${nodeId}`); - farmIds.add((await res.json())["farmId"]); + farmIds.add((await res.json())['farmId']); } let farmIdsarr = Array.from(farmIds); diff --git a/src/utils/getGrid.ts b/src/utils/getGrid.ts index 67c3ab7f..9b58e47a 100644 --- a/src/utils/getGrid.ts +++ b/src/utils/getGrid.ts @@ -1,5 +1,5 @@ -import type { Profile } from 'tf-profile-manager'; import type { GridClient, NetworkEnv } from 'grid3_client'; +import type { Profile } from 'tf-profile-manager'; export default async function getGrid( profile: Profile, diff --git a/src/utils/gqlApi.ts b/src/utils/gqlApi.ts index 8d81d0e3..7873376c 100644 --- a/src/utils/gqlApi.ts +++ b/src/utils/gqlApi.ts @@ -1,25 +1,24 @@ -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from '../stores/activeProfile'; export default function gqlApi( - profile: IProfile, - // name: string, + profile: ActiveProfile, query: string, variables: Object = {} ): Promise { - const { networkEnv } = profile; + const { network } = profile; const grid = new window.configs.grid3_client.GridClient( - "" as any, - "", - "", + '' as any, + '', + '', null ); - const { graphql } = grid.getDefaultUrls(networkEnv as any); + const { graphql } = grid.getDefaultUrls(network); return fetch(graphql, { - method: "POST", + method: 'POST', headers: { - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, body: JSON.stringify({ query, variables }), }) diff --git a/src/utils/hasEnoughBalance.ts b/src/utils/hasEnoughBalance.ts index 2121189c..4e9a9934 100644 --- a/src/utils/hasEnoughBalance.ts +++ b/src/utils/hasEnoughBalance.ts @@ -1,7 +1,7 @@ -import type { IProfile } from "../types/Profile"; +import { get } from 'svelte/store'; export default function hasEnoughBalance(amount = 2) { - // const { balance } = profile; - const balance = window.configs.balanceStore.getBalance(); - return balance && balance >= amount; + const activeProfile = get(window.configs.activeProfileStore); + const value = get(activeProfile.balance); + return value && value.balance && value.balance >= amount; } From fb340fec5de60f95a58bfe8f73c83f62bc91598c Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 15:33:38 +0200 Subject: [PATCH 04/16] Apply Fix to vm --- src/App.svelte | 6 +++--- src/elements/vm/Vm.wc.svelte | 16 +++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 4a3e0fc2..e93b68c8 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,8 +2,8 @@ import Base from './elements/base/Base.wc.svelte'; import ProfileManager from './elements/ProfileManager/ProfileManager.wc.svelte'; - import Fullvm from './elements/fullvm/Fullvm.wc.svelte'; - // import Vm from "./elements/vm/Vm.wc.svelte"; + // import Fullvm from './elements/fullvm/Fullvm.wc.svelte'; + import Vm from './elements/vm/Vm.wc.svelte'; // import Kubernetes from "./elements/kubernetes/Kubernetes.wc.svelte"; // import Caprover from "./elements/caprover/Caprover.wc.svelte"; // import Peertube from "./elements/peertube/Peertube.wc.svelte"; @@ -45,7 +45,7 @@ - + @@ -187,7 +173,6 @@ bind:nodeSelection={data.selection.type} bind:status filters={data.selection.filters} - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> diff --git a/src/utils/deployPeertube.ts b/src/utils/deployPeertube.ts index f7e6eb6d..850350e2 100644 --- a/src/utils/deployPeertube.ts +++ b/src/utils/deployPeertube.ts @@ -1,9 +1,7 @@ import type { default as Peertube } from "../types/peertube"; -import type { IProfile } from "../types/Profile"; import { Network } from "../types/kubernetes"; import { - selectGatewayNode, getUniqueDomainName, selectSpecificGatewayNode, GatewayNodes, @@ -13,10 +11,11 @@ import deploy from "./deploy"; import rootFs from "./rootFs"; import destroy from "./destroy"; import checkVMExist, { checkGW } from "./prepareDeployment"; +import type { ActiveProfile } from "../stores/activeProfile"; export default async function deployPeertube( data: Peertube, - profile: IProfile, + profile: ActiveProfile, gateway: GatewayNodes ) { // gateway model: @@ -43,7 +42,7 @@ export default async function deployPeertube( return { deploymentInfo }; } -async function deployPeertubeVM(profile: IProfile, data: Peertube) { +async function deployPeertubeVM(profile: ActiveProfile, data: Peertube) { const { DiskModel, MachineModel, MachinesModel, generateString } = window.configs.grid3_client; @@ -87,7 +86,7 @@ async function deployPeertubeVM(profile: IProfile, data: Peertube) { vm.flist = "https://hub.grid.tf/tf-official-apps/peertube-v3.1.1.flist"; vm.entrypoint = "/sbin/zinit init"; vm.env = { - SSH_KEY: profile.sshKey, + SSH_KEY: profile.ssh, PEERTUBE_ADMIN_EMAIL: adminEmail, PT_INITIAL_ROOT_PASSWORD: adminPassword, PEERTUBE_WEBSERVER_HOSTNAME: domain, @@ -117,7 +116,7 @@ async function deployPeertubeVM(profile: IProfile, data: Peertube) { } async function deployPrefixGateway( - profile: IProfile, + profile: ActiveProfile, domainName: string, backend: string, publicNodeId: number diff --git a/src/utils/gatewayHelpers.ts b/src/utils/gatewayHelpers.ts index 2e4ff0f1..3f0e9763 100644 --- a/src/utils/gatewayHelpers.ts +++ b/src/utils/gatewayHelpers.ts @@ -1,11 +1,26 @@ +import { get } from "svelte/store"; +import type { ActiveProfile } from "../stores/activeProfile"; import { solutionList } from "../stores/solutionsList"; +import getGrid from "./getGrid"; export interface GatewayNodes { nodeDomain: string; nodeId: number; idx?: number; } + +async function _checkGrid() { + const { GridClient } = window.configs.grid3_client; + + if (!GridClient.config) { + const grid = await getGrid(get(window.configs.activeProfileStore), _ => _); + await grid.connect(); + } +} + export async function selectGatewayNode(): Promise<[number, string]> { + await _checkGrid(); + const { GridClient, Nodes, randomChoice } = window.configs.grid3_client; const nodes = new Nodes( @@ -31,6 +46,8 @@ export function selectSpecificGatewayNode( } export async function LoadGatewayNodes(): Promise { + await _checkGrid(); + const { GridClient, Nodes } = window.configs.grid3_client; const nodes = new Nodes( GridClient.config.graphqlURL, @@ -49,12 +66,14 @@ export async function LoadGatewayNodes(): Promise { return gws; } -export async function getUniqueDomainName(profile, name, solutionType) { - const { networkEnv, mnemonics, storeSecret } = profile; +export async function getUniqueDomainName(profile: ActiveProfile, name, solutionType) { + await _checkGrid(); + + const { network, mnemonics, secret } = profile; const client = new window.configs.grid3_client.GridClient( - networkEnv as any, + network, mnemonics, - storeSecret, + secret, new window.configs.client.HTTPMessageBusClient(0, "", "", ""), solutionType, window.configs.grid3_client.BackendStorageType.tfkvstore From bebe36f9fa894c65c4f31d6614c33970813cde1e Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 16:58:38 +0200 Subject: [PATCH 08/16] Apply Fix to Funkwhale --- src/App.svelte | 6 +++--- src/elements/funkwhale/Funkwhale.wc.svelte | 18 +++--------------- src/utils/deployFunkwhale.ts | 9 ++++----- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 442a0a26..23f44177 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -6,8 +6,8 @@ // import Vm from './elements/vm/Vm.wc.svelte'; // import Kubernetes from './elements/kubernetes/Kubernetes.wc.svelte'; // import Caprover from './elements/caprover/Caprover.wc.svelte'; - import Peertube from './elements/peertube/Peertube.wc.svelte'; - // import Funkwhale from "./elements/funkwhale/Funkwhale.wc.svelte"; + // import Peertube from './elements/peertube/Peertube.wc.svelte'; + import Funkwhale from './elements/funkwhale/Funkwhale.wc.svelte'; // import Mattermost from "./elements/Mattermost/Mattermost.wc.svelte"; // import Discourse from "./elements/discourse/Discourse.wc.svelte"; // import Taiga from "./elements/taiga/Taiga.wc.svelte"; @@ -45,7 +45,7 @@ - + + diff --git a/src/elements/ContractsList/ContractsList.wc.svelte b/src/elements/ContractsList/ContractsList.wc.svelte index 36b9feba..f0701a2d 100644 --- a/src/elements/ContractsList/ContractsList.wc.svelte +++ b/src/elements/ContractsList/ContractsList.wc.svelte @@ -2,10 +2,8 @@ - onLoadProfile(detail)} /> + $: onLoadProfile(profile) +
@@ -226,7 +226,7 @@ >
{#if message} - + {/if}
diff --git a/src/elements/DeployedList/DeployedList.wc.svelte b/src/elements/DeployedList/DeployedList.wc.svelte index 133eb0ed..a8f6c948 100644 --- a/src/elements/DeployedList/DeployedList.wc.svelte +++ b/src/elements/DeployedList/DeployedList.wc.svelte @@ -2,7 +2,6 @@ - { - profile = detail; - if (detail) { - onConfigHandler(); - } - }} -/> + $: if (profile) onConfigHandler() +
diff --git a/src/elements/algorand/Algorand.wc.svelte b/src/elements/algorand/Algorand.wc.svelte index fe873963..46f19c9a 100644 --- a/src/elements/algorand/Algorand.wc.svelte +++ b/src/elements/algorand/Algorand.wc.svelte @@ -2,13 +2,11 @@ - { - profile = detail; - }} -/> -

Deploy a Algorand Instance

@@ -294,7 +287,6 @@ bind:nodeSelection={data.selection.type} bind:status filters={data.selection.filters} - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> diff --git a/src/elements/casperlabs/Casperlabs.wc.svelte b/src/elements/casperlabs/Casperlabs.wc.svelte index a8784ed8..9fea1286 100644 --- a/src/elements/casperlabs/Casperlabs.wc.svelte +++ b/src/elements/casperlabs/Casperlabs.wc.svelte @@ -8,13 +8,11 @@ ITab, SelectCapacityUpdate, } from "../../types"; - import type { IProfile } from "../../types/Profile"; - import { Disk, Env } from "../../types/vm"; + import { Disk } from "../../types/vm"; import Casperlabs from "../../types/casperlabs"; // Modules import deployCasperlabs from "../../utils/deployCasperlabs"; // Components - import SelectProfile from "../../components/SelectProfile.svelte"; import Input from "../../components/Input.svelte"; import Tabs from "../../components/Tabs.svelte"; import SelectNodeId from "../../components/SelectNodeId.svelte"; @@ -42,7 +40,8 @@ let selectCapacity = new SelectCapacityUpdate(); data.disks = [new Disk()]; - let profile: IProfile; + const activeProfile = window.configs?.activeProfileStore; + $: profile = $activeProfile; let active: string = "base"; let loading = false; let success = false; @@ -92,15 +91,6 @@ $: logs = $currentDeployment; - { - profile = detail; - if (detail) { - data.envs[0] = new Env(undefined, "SSH_KEY", detail?.sshKey); - } - }} -/> -

Deploy a Casperlabs Instance

@@ -168,7 +158,6 @@ bind:data={data.nodeId} filters={data.selection.filters} bind:status - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> diff --git a/src/elements/nodePilot/NodePilot.wc.svelte b/src/elements/nodePilot/NodePilot.wc.svelte index 81d22acd..90cc7814 100644 --- a/src/elements/nodePilot/NodePilot.wc.svelte +++ b/src/elements/nodePilot/NodePilot.wc.svelte @@ -6,10 +6,8 @@ import type { IFlist, IFormField, ITab } from "../../types"; import deployVM from "../../utils/deployVM"; - import type { IProfile } from "../../types/Profile"; // Components - import SelectProfile from "../../components/SelectProfile.svelte"; import Input from "../../components/Input.svelte"; import Tabs from "../../components/Tabs.svelte"; import SelectNodeId from "../../components/SelectNodeId.svelte"; @@ -70,11 +68,12 @@ ]; const deploymentStore = window.configs?.deploymentStore; + const activeProfile = window.configs?.activeProfileStore; let active: string = "config"; let loading = false; let success = false; let failed = false; - let profile: IProfile; + $: profile = $activeProfile; let message: string; let modalData: Object; @@ -150,15 +149,6 @@ $: logs = $currentDeployment; - { - profile = detail; - if (detail) { - data.envs[0] = new Env(undefined, "SSH_KEY", detail?.sshKey); - } - }} -/> -

Deploy a Node Pilot

@@ -222,7 +212,6 @@ bind:data={data.nodeId} filters={data.selection.filters} bind:status - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> diff --git a/src/elements/subsquid/Subsquid.wc.svelte b/src/elements/subsquid/Subsquid.wc.svelte index 39290ef0..e48177c4 100644 --- a/src/elements/subsquid/Subsquid.wc.svelte +++ b/src/elements/subsquid/Subsquid.wc.svelte @@ -2,7 +2,6 @@ - { - profile = detail; - }} -/> -

Deploy a Subsquid Archive(s)

@@ -178,7 +171,6 @@ bind:nodeSelection={data.selection.type} bind:status filters={data.selection.filters} - {profile} on:fetch={({ detail }) => (data.selection.nodes = detail)} nodes={data.selection.nodes} /> diff --git a/src/types/deployedList.ts b/src/types/deployedList.ts index 850b8126..c7f15a03 100644 --- a/src/types/deployedList.ts +++ b/src/types/deployedList.ts @@ -1,7 +1,7 @@ import getGrid from "../utils/getGrid"; -import type { IProfile } from "./Profile"; import type { GridClient } from "grid3_client"; import formatConsumption from "../utils/formatConsumption"; +import type { ActiveProfile } from "../stores/activeProfile"; export interface IListReturn { total: number; @@ -137,8 +137,8 @@ export default class DeployedList { }; } - public static async init(profile: IProfile): Promise { - return new DeployedList(await getGrid(profile, (grid) => grid, false)); + public static async init(profile: ActiveProfile): Promise { + return new DeployedList(await getGrid(profile, (grid) => grid)); } public static __filterNames(names: string[]): string[] { diff --git a/src/utils/deleteDeployment.ts b/src/utils/deleteDeployment.ts index efc76c41..5a996f2e 100644 --- a/src/utils/deleteDeployment.ts +++ b/src/utils/deleteDeployment.ts @@ -1,14 +1,9 @@ +import type { ActiveProfile } from "../stores/activeProfile"; import { getUniqueDomainName } from "./gatewayHelpers"; -interface IConfig { - mnemonics: string; - storeSecret: string; - networkEnv: string; -} - export default async function deleteDeployment( - configs: IConfig, + configs: ActiveProfile, key: "k8s" | "machines", name: string, type: string @@ -16,12 +11,12 @@ export default async function deleteDeployment( const { GridClient } = window.configs.grid3_client; const { HTTPMessageBusClient } = window.configs.client; - const { mnemonics, networkEnv, storeSecret } = configs; + const { mnemonics, network, secret } = configs; const http = new HTTPMessageBusClient(0, "", "", ""); const grid = new GridClient( - networkEnv as any, + network, mnemonics, - storeSecret, + secret, http, type, "tfkvstore" as any diff --git a/src/utils/deployAlgorand.ts b/src/utils/deployAlgorand.ts index 7f00594b..96e42d4a 100644 --- a/src/utils/deployAlgorand.ts +++ b/src/utils/deployAlgorand.ts @@ -1,5 +1,5 @@ +import type { ActiveProfile } from "../stores/activeProfile"; import type Algorand from "../types/algorand"; -import type { IProfile } from "../types/Profile"; import { Network } from "../types/kubernetes"; import createNetwork from "./createNetwork"; @@ -9,14 +9,14 @@ import checkVMExist from "./prepareDeployment"; export default async function deployAlgorand( data: Algorand, - profile: IProfile + profile: ActiveProfile ) { const deploymentInfo = await depoloyAlgorandVM(data, profile); return { deploymentInfo }; } -async function depoloyAlgorandVM(data: Algorand, profile: IProfile) { - const { MachinesModel, DiskModel, GridClient, MachineModel, generateString } = +async function depoloyAlgorandVM(data: Algorand, profile: ActiveProfile) { + const { MachinesModel, DiskModel, MachineModel, generateString } = window.configs.grid3_client; const { name, @@ -61,7 +61,7 @@ async function depoloyAlgorandVM(data: Algorand, profile: IProfile) { machine.flist = "https://hub.grid.tf/tf-official-apps/algorand-latest.flist"; machine.entrypoint = "/sbin/zinit init"; machine.env = { - SSH_KEY: profile.sshKey, + SSH_KEY: profile.ssh, NETWORK: nodeNetwork, NODE_TYPE: nodeType, ACCOUNT_MNEMONICS: mnemonics, diff --git a/src/utils/deployCasperlabs.ts b/src/utils/deployCasperlabs.ts index 8359ea56..bdc68a12 100644 --- a/src/utils/deployCasperlabs.ts +++ b/src/utils/deployCasperlabs.ts @@ -1,10 +1,8 @@ import type { default as Casperlabs } from "../types/casperlabs"; -import type { IProfile } from "../types/Profile"; import deploy from "./deploy"; import { - selectGatewayNode, getUniqueDomainName, GatewayNodes, selectSpecificGatewayNode, @@ -14,10 +12,11 @@ import createNetwork from "./createNetwork"; import { Network } from "../types/kubernetes"; import destroy from "./destroy"; import checkVMExist, { checkGW } from "./prepareDeployment"; +import type { ActiveProfile } from "../stores/activeProfile"; export default async function deployCasperlabs( data: Casperlabs, - profile: IProfile, + profile: ActiveProfile, gateway: GatewayNodes ) { // gateway model: @@ -45,7 +44,7 @@ export default async function deployCasperlabs( return { deploymentInfo }; } -async function deployCasperlabsVM(profile: IProfile, data: Casperlabs) { +async function deployCasperlabsVM(profile: ActiveProfile, data: Casperlabs) { const { DiskModel, MachineModel, MachinesModel, generateString } = window.configs.grid3_client; @@ -54,9 +53,7 @@ async function deployCasperlabsVM(profile: IProfile, data: Casperlabs) { cpu, memory, disks: [{ size }], - publicIp, nodeId, - envs, domain, } = data; @@ -86,7 +83,7 @@ async function deployCasperlabsVM(profile: IProfile, data: Casperlabs) { vm.flist = "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist"; vm.entrypoint = "/sbin/zinit init"; vm.env = { - SSH_KEY: profile.sshKey, + SSH_KEY: profile.ssh, CASPERLABS_HOSTNAME: domain, }; @@ -114,7 +111,7 @@ async function deployCasperlabsVM(profile: IProfile, data: Casperlabs) { } async function deployPrefixGateway( - profile: IProfile, + profile: ActiveProfile, domainName: string, backend: string, publicNodeId: number diff --git a/src/utils/deploySubsquid.ts b/src/utils/deploySubsquid.ts index 11521a0c..eb2647a0 100644 --- a/src/utils/deploySubsquid.ts +++ b/src/utils/deploySubsquid.ts @@ -1,9 +1,7 @@ import type { default as Subsquid } from "../types/subsquid"; -import type { IProfile } from "../types/Profile"; import { Network } from "../types/kubernetes"; import { - selectGatewayNode, getUniqueDomainName, GatewayNodes, selectSpecificGatewayNode, @@ -13,10 +11,11 @@ import deploy from "./deploy"; import rootFs from "./rootFs"; import destroy from "./destroy"; import checkVMExist, { checkGW } from "./prepareDeployment"; +import type { ActiveProfile } from "../stores/activeProfile"; export default async function deploySubsquid( data: Subsquid, - profile: IProfile, + profile: ActiveProfile, gateway: GatewayNodes ) { // gateway model: @@ -44,7 +43,7 @@ export default async function deploySubsquid( return { deploymentInfo }; } -async function deploySubsquidVM(profile: IProfile, data: Subsquid) { +async function deploySubsquidVM(profile: ActiveProfile, data: Subsquid) { const { DiskModel, MachineModel, MachinesModel, generateString } = window.configs.grid3_client; @@ -87,7 +86,7 @@ async function deploySubsquidVM(profile: IProfile, data: Subsquid) { vm.flist = "https://hub.grid.tf/tf-official-apps/subsquid-latest.flist"; vm.entrypoint = "/sbin/zinit init"; vm.env = { - SSH_KEY: profile.sshKey, + SSH_KEY: profile.ssh, CHAIN_ENDPOINT: endPoint, SUBSQUID_WEBSERVER_HOSTNAME: domain, }; @@ -116,7 +115,7 @@ async function deploySubsquidVM(profile: IProfile, data: Subsquid) { } async function deployPrefixGateway( - profile: IProfile, + profile: ActiveProfile, domainName: string, backend: string, publicNodeId: number diff --git a/src/utils/getContractsConsumption.ts b/src/utils/getContractsConsumption.ts index bb37e764..818916db 100644 --- a/src/utils/getContractsConsumption.ts +++ b/src/utils/getContractsConsumption.ts @@ -1,5 +1,5 @@ import type { GridClient } from "grid3_client"; -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from "../stores/activeProfile"; import formatConsumption from "./formatConsumption"; import getGrid from "./getGrid"; @@ -21,7 +21,7 @@ function _getConsumption(id: number, grid: GridClient) { } export default function getContractsConsumption( - profile: IProfile, + profile: ActiveProfile, contracts: { id: number }[] ) { return getGrid(profile, (grid) => { From 681e6730672a88ed0744a508e00f694cf15da4cf Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 18:18:00 +0200 Subject: [PATCH 15/16] Fix all missing weblets --- playground/public/index.html | 2 +- playground/src/views/Editor.vue | 2 +- src/components/UpdateCapRover.svelte | 7 +++---- src/components/UpdateK8s.svelte | 9 ++++----- .../ProfileManager/ProfileManager.wc.svelte | 3 ++- .../TFhubValidator/TFhubValidator.wc.svelte | 16 ++-------------- src/utils/deployTFhubValidator.ts | 8 ++++---- src/utils/destroy.ts | 11 +++++------ src/utils/getBalance.ts | 7 +++---- src/utils/nodeExists.ts | 8 ++++---- src/utils/validateMnemonics.ts | 10 +++++----- src/utils/validateNode.ts | 4 ++-- 12 files changed, 36 insertions(+), 51 deletions(-) diff --git a/playground/public/index.html b/playground/public/index.html index 04212191..e0f9adc3 100644 --- a/playground/public/index.html +++ b/playground/public/index.html @@ -9,7 +9,7 @@ - +
diff --git a/src/components/UpdateCapRover.svelte b/src/components/UpdateCapRover.svelte index 066c27cb..539f7eb7 100644 --- a/src/components/UpdateCapRover.svelte +++ b/src/components/UpdateCapRover.svelte @@ -2,7 +2,6 @@ - { - profile = detail; - if (detail) { - data.ssh_key = detail?.sshKey; - } - }} -/> -

Deploy a TFhub Validator Instance

@@ -197,7 +186,6 @@ bind:data={data.nodeId} bind:status={data.status} bind:nodeSelection={data.selection.type} - {profile} cpu={data.cpu} ssd={data.disks.reduce( (total, disk) => total + disk.size, diff --git a/src/utils/deployTFhubValidator.ts b/src/utils/deployTFhubValidator.ts index f824a322..aeaa9a28 100644 --- a/src/utils/deployTFhubValidator.ts +++ b/src/utils/deployTFhubValidator.ts @@ -1,5 +1,4 @@ import type TFhubValidator from "../types/TFhubValidator"; -import type { IProfile } from "../types/Profile"; import { Network } from "../types/kubernetes"; import createNetwork from "./createNetwork"; @@ -7,10 +6,11 @@ import deploy from "./deploy"; import rootFs from "./rootFs"; import checkVMExist from "./prepareDeployment"; import { configVariables, setStakeAmount, getNetwork } from "../utils/tfhubValidatorConf" +import type { ActiveProfile } from "../stores/activeProfile"; export default async function deployTFhubValidator( - profile: IProfile, + profile: ActiveProfile, tfhubValidator: TFhubValidator ) { @@ -22,7 +22,7 @@ export default async function deployTFhubValidator( } function _deployTfHubValidator( - profile: IProfile, tfhubValidator: TFhubValidator + profile: ActiveProfile, tfhubValidator: TFhubValidator ) { const { @@ -89,7 +89,7 @@ function _deployTfHubValidator( GAS_PRICES: gas_prices, GAS_ADJUSTMENT: gas_adjustment, ORCHESTRATOR_FEES: orchestrator_fees, - SSH_KEY: profile.sshKey, + SSH_KEY: profile.ssh, }; const vms = new MachinesModel(); diff --git a/src/utils/destroy.ts b/src/utils/destroy.ts index f54e32f2..a402f37f 100644 --- a/src/utils/destroy.ts +++ b/src/utils/destroy.ts @@ -1,12 +1,11 @@ -import type { IProfile } from "../types/Profile"; -import type { IStore } from "../stores/currentDeployment"; +import type { ActiveProfile } from "../stores/activeProfile"; -export default function destroy(profile: IProfile, type: string, name: string) { - const { networkEnv, mnemonics, storeSecret } = profile; +export default function destroy(profile: ActiveProfile, type: string, name: string) { + const { network, mnemonics, secret } = profile; const client = new window.configs.grid3_client.GridClient( - networkEnv as any, + network, mnemonics, - storeSecret, + secret, new window.configs.client.HTTPMessageBusClient(0, "", "", ""), type, window.configs.grid3_client.BackendStorageType.tfkvstore diff --git a/src/utils/getBalance.ts b/src/utils/getBalance.ts index 70aac1ac..88493afb 100644 --- a/src/utils/getBalance.ts +++ b/src/utils/getBalance.ts @@ -1,7 +1,7 @@ -import type { IProfile } from "../types/Profile"; -import getGrid from "./getGrid"; +import type { ActiveProfile } from '../stores/activeProfile'; +import getGrid from './getGrid'; -export default async function getBalance(profile: IProfile) { +export default async function getBalance(profile: ActiveProfile) { if (!profile) return null; return getGrid(profile, (grid) => { @@ -11,4 +11,3 @@ export default async function getBalance(profile: IProfile) { .then((res) => res); }); } - diff --git a/src/utils/nodeExists.ts b/src/utils/nodeExists.ts index 758fb34e..b8c4606f 100644 --- a/src/utils/nodeExists.ts +++ b/src/utils/nodeExists.ts @@ -1,9 +1,9 @@ -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from "../stores/activeProfile"; -export default async function nodeExists(profile: IProfile, nodeId:number) : Promise { - const { networkEnv } = profile; +export default async function nodeExists(profile: ActiveProfile, nodeId:number) : Promise { + const { network } = profile; - return fetch(`https://gridproxy.${networkEnv}.grid.tf/nodes/${nodeId}`, { + return fetch(`https://gridproxy.${network}.grid.tf/nodes/${nodeId}`, { method: "GET", }) .then((res) => {console.log(res); return (res.status >= 200 && res.status < 400) ? true : false}) diff --git a/src/utils/validateMnemonics.ts b/src/utils/validateMnemonics.ts index f017bb62..e40880c5 100644 --- a/src/utils/validateMnemonics.ts +++ b/src/utils/validateMnemonics.ts @@ -1,12 +1,12 @@ -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from "../stores/activeProfile"; -export default function validateMnemonics(profile: IProfile) { - const { networkEnv, mnemonics, storeSecret } = profile; +export default function validateMnemonics(profile: ActiveProfile) { + const { network, mnemonics, secret } = profile; const http = new window.configs.client.HTTPMessageBusClient(0, "", "", ""); const grid = new window.configs.grid3_client.GridClient( - networkEnv as any, + network, mnemonics, - storeSecret, + secret, http, undefined, "tfkvstore" as any diff --git a/src/utils/validateNode.ts b/src/utils/validateNode.ts index 2c409e52..26a311bf 100644 --- a/src/utils/validateNode.ts +++ b/src/utils/validateNode.ts @@ -1,8 +1,8 @@ -import type { IProfile } from "../types/Profile"; +import type { ActiveProfile } from "../stores/activeProfile"; import findNodes from "./findNodes"; export default function validateNode( - profile: IProfile, + profile: ActiveProfile, cru: number, mru: number, sru: number, From 212c17ac383f63a681949df23c06ed59f1fd40f0 Mon Sep 17 00:00:00 2001 From: MohamedElmdary Date: Thu, 27 Oct 2022 18:21:21 +0200 Subject: [PATCH 16/16] Remove un-used variables --- src/elements/DeployedList/DeployedList.wc.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/elements/DeployedList/DeployedList.wc.svelte b/src/elements/DeployedList/DeployedList.wc.svelte index a8f6c948..2d76f044 100644 --- a/src/elements/DeployedList/DeployedList.wc.svelte +++ b/src/elements/DeployedList/DeployedList.wc.svelte @@ -640,7 +640,6 @@ {#if k8sToUpdate} { k8sToUpdate = null; @@ -651,7 +650,6 @@ {#if capRoverToUpdate} { capRoverToUpdate = null;