Browse Source

Flesh out a bit more of the import and also refactor the router

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
65381e103c
  1. 20
      src/router/index.ts
  2. 64
      src/views/ImportAccountView.vue

20
src/router/index.ts

@ -115,22 +115,20 @@ router.beforeEach(async (to, from, next) => {
const publicPages = ["/start", "/account", "/import-account"]; const publicPages = ["/start", "/account", "/import-account"];
const isPublic = publicPages.includes(to.path); const isPublic = publicPages.includes(to.path);
const appStore = useAppStore(); const appStore = useAppStore();
let return_path = "/start"; console.log(to);
if (to.path === "/" && appStore.condition == "registered") { if (to.path === "/" && appStore.condition === "registered") {
return_path = "/account"; next({ path: "/account" });
} } else if (isPublic) {
if (isPublic) {
switch (appStore.condition) { switch (appStore.condition) {
case "uninitialized":
return_path = "";
break;
case "registered": case "registered":
next(); next();
break; break;
default:
next();
break;
} }
} } else if (appStore.condition === "uninitialized") {
if (return_path == "") { next({ path: "/start" });
return;
} else { } else {
next(); next();
} }

64
src/views/ImportAccountView.vue

@ -14,49 +14,59 @@
</h1> </h1>
</div> </div>
<!-- Import Account Form --> <!-- Import Account Form -->
<form> <p class="text-center text-xl mb-4 font-light">
<p class="text-center text-xl mb-4 font-light"> Enter your seed phrase below to import your identity on this device.
Enter your seed phrase below to import your identity on this device. </p>
</p> <input
<input type="text"
type="text" placeholder="Seed Phrase"
placeholder="Seed Phrase" class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2" v-bind="mnemonic"
value="{{ mnemonic }}" />
/> <div class="mt-8">
<div class="mt-8"> <button
<button` @click="from_mnemonic()"
@click="import(mnemonic)" class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2" >
value="Import Identity" Import
/> </button>
<button <button
@click="onCancelClick()" @click="onCancelClick()"
type="button" type="button"
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md" class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
> >
Cancel Cancel
</button> </button>
</div> </div>
</form>
</section> </section>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { deriveAddress } from "../libs/crypto";
@Options({ @Options({
components: {}, components: {},
}) })
export default class ImportAccountView extends Vue { export default class ImportAccountView extends Vue {
mnemonic = ""; mnemonic = "";
address = "";
privateHex = "";
publicHex = "";
UPORT_ROOT_DERIVATION_PATH = "";
public onCancelClick() { public onCancelClick() {
this.$router.back(); this.$router.back();
} }
public import() { public from_mnemonic() {
// just to get rid of variability that might cause an error
if (this.mnemonic.trim().length > 0) { if (this.mnemonic.trim().length > 0) {
this.mnemonic = this.mnemonic.trim().toLowerCase(); this.mnemonic = this.mnemonic.trim().toLowerCase();
[
this.address,
this.privateHex,
this.publicHex,
this.UPORT_ROOT_DERIVATION_PATH,
] = deriveAddress(this.mnemonic);
} }
} }
} }

Loading…
Cancel
Save