|
@ -111,8 +111,8 @@ |
|
|
<div class="text-slate-500 text-sm font-bold">Derivation Path</div> |
|
|
<div class="text-slate-500 text-sm font-bold">Derivation Path</div> |
|
|
<div class="text-sm text-slate-500 mb-1"> |
|
|
<div class="text-sm text-slate-500 mb-1"> |
|
|
<span |
|
|
<span |
|
|
><code>{{ UPORT_ROOT_DERIVATION_PATH }}</code> |
|
|
><code>{{ derivationPath }}</code> |
|
|
<button @click="copy(UPORT_ROOT_DERIVATION_PATH)"> |
|
|
<button @click="copy(derivationPath)"> |
|
|
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa> |
|
|
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa> |
|
|
</button> |
|
|
</button> |
|
|
</span> |
|
|
</span> |
|
@ -168,86 +168,158 @@ |
|
|
</button> |
|
|
</button> |
|
|
</form> |
|
|
</form> |
|
|
</dialog> |
|
|
</dialog> |
|
|
|
|
|
|
|
|
|
|
|
<h3 class="text-sm uppercase font-semibold mb-3">Advanced</h3> |
|
|
|
|
|
|
|
|
|
|
|
<div class="flex"> |
|
|
|
|
|
<button |
|
|
|
|
|
href="" |
|
|
|
|
|
class="text-center text-md text-white px-1.5 py-2 rounded-md mb-6" |
|
|
|
|
|
v-bind:class="showContactGivesClassNames()" |
|
|
|
|
|
@click="toggleShowContactAmounts" |
|
|
|
|
|
> |
|
|
|
|
|
{{ showContactGives ? "Showing" : "Hiding" }} |
|
|
|
|
|
amounts given with contacts (Click to |
|
|
|
|
|
{{ showContactGives ? "hide" : "show" }}) |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div v-bind:class="computedAlertClassNames()"> |
|
|
|
|
|
<button |
|
|
|
|
|
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2" |
|
|
|
|
|
@click="onClickClose()" |
|
|
|
|
|
> |
|
|
|
|
|
<fa icon="xmark"></fa> |
|
|
|
|
|
</button> |
|
|
|
|
|
<h4 class="font-bold pr-5">{{ alertTitle }}</h4> |
|
|
|
|
|
<p>{{ alertMessage }}</p> |
|
|
|
|
|
</div> |
|
|
</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 { useClipboard } from "@vueuse/core"; |
|
|
import { useClipboard } from "@vueuse/core"; |
|
|
import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto"; |
|
|
import { db } from "@/db"; |
|
|
import { db } from "../db"; |
|
|
import { MASTER_SETTINGS } from "@/db/tables"; |
|
|
import { useAppStore } from "@/store/app"; |
|
|
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto"; |
|
|
import { ref } from "vue"; |
|
|
|
|
|
//import { testServerRegisterUser } from "../test"; |
|
|
//import { testServerRegisterUser } from "../test"; |
|
|
|
|
|
|
|
|
@Options({ |
|
|
@Options({ |
|
|
components: {}, |
|
|
components: {}, |
|
|
}) |
|
|
}) |
|
|
export default class AccountViewView extends Vue { |
|
|
export default class AccountViewView extends Vue { |
|
|
firstName = |
|
|
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser() |
|
|
localStorage.getItem("firstName") === null |
|
|
//testRegisterUser = testServerRegisterUser; |
|
|
? "--" |
|
|
|
|
|
: localStorage.getItem("firstName"); |
|
|
|
|
|
lastName = |
|
|
|
|
|
localStorage.getItem("lastName") === null |
|
|
|
|
|
? "--" |
|
|
|
|
|
: localStorage.getItem("lastName"); |
|
|
|
|
|
mnemonic = ""; |
|
|
|
|
|
address = ""; |
|
|
address = ""; |
|
|
privateHex = ""; |
|
|
firstName = ""; |
|
|
|
|
|
lastName = ""; |
|
|
|
|
|
mnemonic = ""; |
|
|
publicHex = ""; |
|
|
publicHex = ""; |
|
|
UPORT_ROOT_DERIVATION_PATH = ""; |
|
|
derivationPath = ""; |
|
|
source = ref("Hello"); |
|
|
showContactGives = false; |
|
|
copy = useClipboard().copy; |
|
|
|
|
|
|
|
|
|
|
|
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser() |
|
|
copy = useClipboard().copy; |
|
|
//testRegisterUser = testServerRegisterUser; |
|
|
|
|
|
|
|
|
|
|
|
// 'created' hook runs when the Vue instance is first created |
|
|
// 'created' hook runs when the Vue instance is first created |
|
|
async created() { |
|
|
async created() { |
|
|
const appCondition = useAppStore().condition; |
|
|
await db.open(); |
|
|
if (appCondition == "uninitialized") { |
|
|
try { |
|
|
this.mnemonic = createIdentifier(); |
|
|
const settings = await db.settings.get(MASTER_SETTINGS); |
|
|
[ |
|
|
if (settings) { |
|
|
this.address, |
|
|
this.firstName = settings.firstName || ""; |
|
|
this.privateHex, |
|
|
this.lastName = settings.lastName || ""; |
|
|
this.publicHex, |
|
|
this.showContactGives = !!settings.showContactGivesInline; |
|
|
this.UPORT_ROOT_DERIVATION_PATH, |
|
|
|
|
|
] = deriveAddress(this.mnemonic); |
|
|
|
|
|
|
|
|
|
|
|
const newId = newIdentifier( |
|
|
|
|
|
this.address, |
|
|
|
|
|
this.publicHex, |
|
|
|
|
|
this.privateHex, |
|
|
|
|
|
this.UPORT_ROOT_DERIVATION_PATH |
|
|
|
|
|
); |
|
|
|
|
|
try { |
|
|
|
|
|
await db.open(); |
|
|
|
|
|
const num_accounts = await db.accounts.count(); |
|
|
|
|
|
if (num_accounts === 0) { |
|
|
|
|
|
await db.accounts.add({ |
|
|
|
|
|
publicKey: newId.keys[0].publicKeyHex, |
|
|
|
|
|
mnemonic: this.mnemonic, |
|
|
|
|
|
identity: JSON.stringify(newId), |
|
|
|
|
|
dateCreated: new Date().getTime(), |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
useAppStore().setCondition("registered"); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const numAccounts = await db.accounts.count(); |
|
|
|
|
|
if (numAccounts === 0) { |
|
|
|
|
|
let privateHex = ""; |
|
|
|
|
|
this.mnemonic = generateSeed(); |
|
|
|
|
|
[this.address, privateHex, this.publicHex, this.derivationPath] = |
|
|
|
|
|
deriveAddress(this.mnemonic); |
|
|
|
|
|
|
|
|
|
|
|
const newId = newIdentifier( |
|
|
|
|
|
this.address, |
|
|
|
|
|
this.publicHex, |
|
|
|
|
|
privateHex, |
|
|
|
|
|
this.derivationPath |
|
|
|
|
|
); |
|
|
|
|
|
await db.accounts.add({ |
|
|
|
|
|
dateCreated: new Date().toISOString(), |
|
|
|
|
|
derivationPath: this.derivationPath, |
|
|
|
|
|
identity: JSON.stringify(newId), |
|
|
|
|
|
mnemonic: this.mnemonic, |
|
|
|
|
|
publicKeyHex: newId.keys[0].publicKeyHex, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
this.alertMessage = |
|
|
|
|
|
"Clear your cache and start over (after data backup). See console log for more info."; |
|
|
|
|
|
console.log("Telling user to clear cache because:", err); |
|
|
|
|
|
this.alertTitle = "Error Creating Account"; |
|
|
|
|
|
this.isAlertVisible = true; |
|
|
} |
|
|
} |
|
|
await db.open(); |
|
|
|
|
|
const num_accounts = await db.accounts.count(); |
|
|
const accounts = await db.accounts.toArray(); |
|
|
if (num_accounts === 0) { |
|
|
const identity = JSON.parse(accounts[0].identity); |
|
|
console.log("Problem! Should have a profile!"); |
|
|
this.address = identity.did; |
|
|
} else { |
|
|
this.publicHex = identity.keys[0].publicKeyHex; |
|
|
const accounts = await db.accounts.toArray(); |
|
|
this.derivationPath = identity.keys[0].meta.derivationPath; |
|
|
const identity = JSON.parse(accounts[0].identity); |
|
|
} |
|
|
this.address = identity.did; |
|
|
|
|
|
this.publicHex = identity.keys[0].publicKeyHex; |
|
|
public async toggleShowContactAmounts() { |
|
|
this.UPORT_ROOT_DERIVATION_PATH = identity.keys[0].meta.derivationPath; |
|
|
this.showContactGives = !this.showContactGives; |
|
|
|
|
|
try { |
|
|
|
|
|
await db.open(); |
|
|
|
|
|
const settings = await db.settings.get(MASTER_SETTINGS); |
|
|
|
|
|
if (settings) { |
|
|
|
|
|
db.settings.update(MASTER_SETTINGS, { |
|
|
|
|
|
showContactGivesInline: this.showContactGives, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
this.alertMessage = |
|
|
|
|
|
"Clear your cache and start over (after data backup). See console log for more info."; |
|
|
|
|
|
console.log("Telling user to clear cache because:", err); |
|
|
|
|
|
this.alertTitle = "Error Creating Account"; |
|
|
|
|
|
this.isAlertVisible = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public showContactGivesClassNames() { |
|
|
|
|
|
return { |
|
|
|
|
|
"bg-slate-900": !this.showContactGives, |
|
|
|
|
|
"bg-green-600": this.showContactGives, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
alertMessage = ""; |
|
|
|
|
|
alertTitle = ""; |
|
|
|
|
|
isAlertVisible = false; |
|
|
|
|
|
|
|
|
|
|
|
public onClickClose() { |
|
|
|
|
|
this.isAlertVisible = false; |
|
|
|
|
|
this.alertTitle = ""; |
|
|
|
|
|
this.alertMessage = ""; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public computedAlertClassNames() { |
|
|
|
|
|
return { |
|
|
|
|
|
hidden: !this.isAlertVisible, |
|
|
|
|
|
"dismissable-alert": true, |
|
|
|
|
|
"bg-slate-100": true, |
|
|
|
|
|
"p-5": true, |
|
|
|
|
|
rounded: true, |
|
|
|
|
|
"drop-shadow-lg": true, |
|
|
|
|
|
absolute: true, |
|
|
|
|
|
"top-3": true, |
|
|
|
|
|
"inset-x-3": true, |
|
|
|
|
|
"transition-transform": true, |
|
|
|
|
|
"ease-in": true, |
|
|
|
|
|
"duration-300": true, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|