From e7769d05bbcd6a88ce0114dea4ea1b1538b74cf5 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 13 Sep 2019 17:57:57 -0700 Subject: [PATCH] WIP added a bunch of possible dynamic loading code, can't tell if it works. Some is commented out, some is not, some commented code is from the original imports --- src/components/ModalAccessByPrivateKey.vue | 54 ++++++++++++++++++---- src/components/ModalCreateByPhrase.vue | 1 + src/views/AccessMyAccount.vue | 5 +- vue.config.js | 5 ++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/components/ModalAccessByPrivateKey.vue b/src/components/ModalAccessByPrivateKey.vue index e5a92738a..965f9771c 100644 --- a/src/components/ModalAccessByPrivateKey.vue +++ b/src/components/ModalAccessByPrivateKey.vue @@ -44,9 +44,11 @@ import { createComponent, SetupContext, PropType, - watch + watch, + ref } from "@vue/composition-api"; -import { Ed25519PrivateKey } from "@hashgraph/sdk"; + +// import { Ed25519PrivateKey } from "@hashgraph/sdk"; export interface State { modalIsOpen: boolean; @@ -76,13 +78,35 @@ export default createComponent({ state: (Object as unknown) as PropType }, setup(props: { state: State }, context: SetupContext) { - const valid = computed(() => { - if (props.state.rawPrivateKey.length === 0) { - // Back out now if we have an empty value - return false; - } + // const valid = computed(() => { + // if (props.state.rawPrivateKey.length === 0) { + // // Back out now if we have an empty value + // return false; + // } + + // try { + // Ed25519PrivateKey.fromString(props.state.rawPrivateKey); + // return true; + // } catch (error) { + // if (error instanceof Error) { + // // The exception message changes depending on the input + // if ( + // error.message === + // "invalid private key: " + props.state.rawPrivateKey + // ) { + // return false; + // } + // } + // throw error; + // } + // }); + + const valid = ref(false); + + async function isValid(): Promise { try { + const { Ed25519PrivateKey } = await import("@hashgraph/sdk"); Ed25519PrivateKey.fromString(props.state.rawPrivateKey); return true; } catch (error) { @@ -98,7 +122,21 @@ export default createComponent({ throw error; } - }); + } + + watch( + () => props.state.rawPrivateKey, + (newVal: string) => { + if (props.state.rawPrivateKey.length === 0) { + // Back out now if we have an empty value + valid.value = false; + } + + isValid().then(result => { + valid.value = result; + }); + } + ); function handleModalChangeIsOpen(isOpen: boolean): void { context.emit("change", { ...props.state, modalIsOpen: isOpen }); diff --git a/src/components/ModalCreateByPhrase.vue b/src/components/ModalCreateByPhrase.vue index 3c4defb9f..4866d0120 100644 --- a/src/components/ModalCreateByPhrase.vue +++ b/src/components/ModalCreateByPhrase.vue @@ -94,6 +94,7 @@ import { SetupContext } from "@vue/composition-api"; import { MnemonicResult, Ed25519PrivateKey } from "@hashgraph/sdk/src/Keys"; +// type MnemonicResult = import("@hashgraph/sdk/src/Keys").MnemonicResult; interface Props { isOpen: boolean; diff --git a/src/views/AccessMyAccount.vue b/src/views/AccessMyAccount.vue index 471a5811d..5634db63d 100644 --- a/src/views/AccessMyAccount.vue +++ b/src/views/AccessMyAccount.vue @@ -65,7 +65,10 @@ import ModalAccessBySoftware, { AccessSoftwareOption } from "../components/ModalAccessBySoftware.vue"; import ModalAccessByPhrase from "../components/ModalAccessByPhrase.vue"; -import ModalAccessByPrivateKey from "../components/ModalAccessByPrivateKey.vue"; +const ModalAccessByPrivateKey = (): Promise< + typeof import("/home/shenglong/Documents/dev/myhbarwallet/src/components/ModalAccessByPrivateKey.vue") +> => import("../components/ModalAccessByPrivateKey.vue"); +// import ModalAccessByPrivateKey from "../components/ModalAccessByPrivateKey.vue"; import ModalEnterAccountId from "../components/ModalEnterAccountId.vue"; import PageTitle from "../components/PageTitle.vue"; import ModalKeystoreFilePassword from "../components/ModalKeystoreFilePassword.vue"; diff --git a/vue.config.js b/vue.config.js index 01b0fdd8f..0ab813083 100644 --- a/vue.config.js +++ b/vue.config.js @@ -19,6 +19,11 @@ module.exports = { HEDERA_NETWORK: `"${process.env.HEDERA_NETWORK || "testnet"}"` }) ] + // , + // entry: { + // home: "./src/app.vue", + // access: "./src/views/AccessMyAccount.vue" + // } }, chainWebpack(config) { // Use a standard HTML template instead of rolling our own (which is default)