Skip to content

Commit

Permalink
chore: Merge branch 'development' into development_farms_not_displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedElmdary committed Dec 20, 2023
2 parents a9caa88 + dee19f8 commit 0e74db1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/grid_client/scripts/caprover_leader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function main() {
SWM_NODE_MODE: "leader",
CAPROVER_ROOT_DOMAIN: "rafy.grid.tf", // update me
DEFAULT_PASSWORD: "captain42",
CAPTAIN_IMAGE_VERSION: "latest",
CAPTAIN_IMAGE_VERSION: "1.10.1",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/scripts/caprover_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function main() {
PUBLIC_KEY: config.ssh_key,
SWM_NODE_MODE: "worker",
LEADER_PUBLIC_IP: "185.206.122.157",
CAPTAIN_IMAGE_VERSION: "latest",
CAPTAIN_IMAGE_VERSION: "1.10.1",
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions packages/playground/src/stores/profile_manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { KeypairType } from "@threefold/grid_client";
import { defineStore } from "pinia";

import { useGrid } from "./grid";
Expand All @@ -9,6 +10,7 @@ export interface Profile {
address: string;
relay: string;
pk: string;
keypairType: KeypairType | undefined;
}

interface State {
Expand Down
10 changes: 7 additions & 3 deletions packages/playground/src/utils/grid.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { BackendStorageType, GridClient, NetworkEnv } from "@threefold/grid_client";
import { BackendStorageType, GridClient, KeypairType, NetworkEnv } from "@threefold/grid_client";

import type { Profile } from "../stores/profile_manager";

const network = (process.env.NETWORK as NetworkEnv) || window.env.NETWORK;

export async function getGrid(profile: Pick<Profile, "mnemonic">, projectName?: string) {
export async function getGrid(
profile: Pick<Profile, "mnemonic"> & Partial<Pick<Profile, "keypairType">>,
projectName?: string,
) {
if (!profile) return null;
const grid = new GridClient({
mnemonic: profile.mnemonic,
network,
backendStorageType: BackendStorageType.tfkvstore,
keypairType: profile.keypairType || KeypairType.sr25519,
projectName,

...(import.meta.env.DEV && network !== NetworkEnv.custom
Expand Down Expand Up @@ -95,6 +98,7 @@ export async function loadProfile(grid: GridClient): Promise<Profile> {
address: grid.tfclient.address,
relay: grid.getDefaultUrls(network).relay.slice(6),
pk: (await grid.twins.get({ id: grid!.twinId })).pk,
keypairType: grid.clientOptions!.keypairType,
};
}

Expand Down
68 changes: 53 additions & 15 deletions packages/playground/src/weblets/profile_manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@
the password. Mnemonic or Hex Seed will never be shared outside of this device.
</p>
</v-alert>

<v-alert variant="tonal" type="info" class="mb-6" v-if="keypairType === KeypairType.ed25519">
<p>
Please note that generation of ed25519 Keys isn't supported, you can only import pre existing ones.
</p>
</v-alert>

<VTooltip
v-if="activeTab === 1"
text="Mnemonic or Hex Seed are your private key. They are used to represent you on the ThreeFold Grid. You can paste existing (Mnemonic or Hex Seed) or click the 'Create Account' button to create an account and generate mnemonic."
Expand Down Expand Up @@ -127,23 +134,36 @@
ref="mnemonicInput"
:disable-validation="creatingAccount || activatingAccount || activating"
>
<div v-bind="tooltipProps">
<VTextField
label="Mnemonic or Hex Seed"
placeholder="Please insert your Mnemonic or Hex Seed"
v-model="mnemonic"
v-bind="{ ...passwordInputProps, ...validationProps }"
:disabled="creatingAccount || activatingAccount || activating"
/>
</div>
<v-row>
<v-col cols="10">
<div v-bind="tooltipProps">
<VTextField
label="Mnemonic or Hex Seed"
placeholder="Please insert your Mnemonic or Hex Seed"
v-model="mnemonic"
v-bind="{ ...passwordInputProps, ...validationProps }"
:disabled="creatingAccount || activatingAccount || activating"
/>
</div>
</v-col>
<v-col cols="2">
<v-autocomplete
:items="[...keyType]"
item-title="name"
v-model="keypairType"
v-if="activeTab === 1"
/>
</v-col>
</v-row>

<div class="d-flex justify-end mb-10">
<v-tooltip>
<template v-slot:activator="{ isActive, props }">
<VBtn
class="mt-2 ml-3"
color="primary"
variant="tonal"
:disabled="!shouldActivateAccount"
:disabled="!shouldActivateAccount || keypairType === KeypairType.ed25519"
:loading="activatingAccount"
@click="openAcceptTerms = termsLoading = true"
v-bind="props"
Expand All @@ -159,7 +179,9 @@
class="mt-2 ml-3"
color="secondary"
variant="tonal"
:disabled="isValidForm || !!mnemonic || shouldActivateAccount"
:disabled="
isValidForm || !!mnemonic || shouldActivateAccount || keypairType === KeypairType.ed25519
"
:loading="creatingAccount"
@click="openAcceptTerms = termsLoading = true"
>
Expand Down Expand Up @@ -252,6 +274,9 @@
<v-alert type="error" variant="tonal" class="mt-2 mb-4" v-if="loginError">
{{ loginError }}
</v-alert>
<v-alert variant="tonal" type="warning" class="mb-6" v-if="activeTab === 1">
<p>Using different keypair types will lead to a completely different account.</p>
</v-alert>
</FormValidator>

<div class="d-flex justify-center mt-2">
Expand Down Expand Up @@ -404,6 +429,7 @@

<script lang="ts" setup>
import { isAddress } from "@polkadot/util-crypto";
import { KeypairType } from "@threefold/grid_client";
import { validateMnemonic } from "bip39";
import Cryptr from "cryptr";
import md5 from "md5";
Expand Down Expand Up @@ -434,6 +460,8 @@ interface Credentials {
passwordHash?: string;
mnemonicHash?: string;
}
const keyType = ["sr25519", "ed25519"];
const keypairType = ref(KeypairType.sr25519);
const theme = useTheme();
Expand Down Expand Up @@ -471,6 +499,15 @@ function handleModelValue(m: boolean) {
});
}
}
watch(
() => keypairType.value,
async (value, oldValue) => {
if (value !== oldValue) {
mnemonicInput.value?.validate();
}
},
{ deep: false },
);
function mounted() {
if (isStoredCredentials()) {
Expand Down Expand Up @@ -536,8 +573,9 @@ const ssh = ref("");
const mnemonicInput = useInputRef();
const shouldActivateAccount = computed(
() =>
mnemonicInput.value?.error?.toLowerCase()?.includes("couldn't get the user twin for the provided mnemonic") ||
false,
mnemonicInput.value?.error
?.toLowerCase()
?.includes("couldn't get the user twin for the provided mnemonic and keytype") || false,
);
let sshTimeout: any;
const isValidConnectConfirmationPassword = computed(() =>
Expand Down Expand Up @@ -616,7 +654,7 @@ async function activate(mnemonic: string) {
activating.value = true;
sessionStorage.setItem("password", password.value);
try {
const grid = await getGrid({ mnemonic });
const grid = await getGrid({ mnemonic, keypairType: keypairType.value });
const profile = await loadProfile(grid!);
ssh.value = profile.ssh;
profileManager.set({ ...profile, mnemonic });
Expand All @@ -628,7 +666,7 @@ async function activate(mnemonic: string) {
}
function validateMnInput(mnemonic: string) {
return getGrid({ mnemonic })
return getGrid({ mnemonic, keypairType: keypairType.value })
.then(() => undefined)
.catch(e => {
return { message: normalizeError(e, "Something went wrong. please try again.") };
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/weblets/tf_caprover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function deploy() {
normalizeCaproverWorker(leader.value, [
{ key: "SWM_NODE_MODE", value: "leader" },
{ key: "CAPROVER_ROOT_DOMAIN", value: domain.value },
{ key: "CAPTAIN_IMAGE_VERSION", value: "latest" },
{ key: "CAPTAIN_IMAGE_VERSION", value: "1.10.1" },
{ key: "PUBLIC_KEY", value: profileManager.profile!.ssh },
{ key: "DEFAULT_PASSWORD", value: password.value },
{ key: "CAPTAIN_IS_DEBUG", value: "true" },
Expand Down
2 changes: 1 addition & 1 deletion packages/weblets/src/utils/deployCaprover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default async function deployCaprover(data: Caprover, profile: IProfile)
machine.env = {
SWM_NODE_MODE: "leader",
CAPROVER_ROOT_DOMAIN: domain,
CAPTAIN_IMAGE_VERSION: "latest",
CAPTAIN_IMAGE_VERSION: "1.10.1",
PUBLIC_KEY: publicKey,
DEFAULT_PASSWORD: password,
CAPTAIN_IS_DEBUG: "true",
Expand Down

0 comments on commit 0e74db1

Please sign in to comment.