Browse Source

allow to switch between accounts

pull/15/head
Trent Larson 2 years ago
parent
commit
1279ff050c
  1. 2
      project.yaml
  2. 72
      src/views/AccountViewView.vue
  3. 2
      src/views/ContactAmountsView.vue
  4. 6
      src/views/ImportAccountView.vue
  5. 6
      src/views/NewEditAccountView.vue

2
project.yaml

@ -14,6 +14,7 @@
- contacts v1 : - contacts v1 :
- test confirmed vs unconfirmed amounts - test confirmed vs unconfirmed amounts
- allow to confirm received gives - allow to confirm received gives
- .2 warn about amounts when you cannot see them
- remove 'copy' until it works - remove 'copy' until it works
- switch to prod server - switch to prod server
- 01 show gives with confirmations - 01 show gives with confirmations
@ -24,7 +25,6 @@
- get 'copy' to work on account page - get 'copy' to work on account page
- contacts v+ : - contacts v+ :
- .2 warn about amounts when you cannot see them
- .2 confirmed direction is wrong on ContactAmounts screen - .2 confirmed direction is wrong on ContactAmounts screen
- .5 make advanced "show/hide amounts" button into a nice UI toggle - .5 make advanced "show/hide amounts" button into a nice UI toggle
- .2 show error to user when adding a duplicate contact - .2 show error to user when adding a duplicate contact

72
src/views/AccountViewView.vue

@ -91,8 +91,8 @@
class="text-sm text-slate-500 flex justify-between items-center mb-1" class="text-sm text-slate-500 flex justify-between items-center mb-1"
> >
<span <span
><code>{{ address }}</code> ><code>{{ activeDid }}</code>
<button @click="copy(address)"> <button @click="copy(activeDid)">
<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>
@ -202,11 +202,8 @@
</button> </button>
</div> </div>
<div class="flex"> <div class="flex py-2">
<button <button class="text-center text-md text-blue-500" @click="checkLimits()">
class="text-center text-md text-blue-500 px-1.5 py-2"
@click="checkLimits()"
>
Check Limits Check Limits
</button> </button>
<div v-if="!!limits?.nextWeekBeginDateTime" class="px-9"> <div v-if="!!limits?.nextWeekBeginDateTime" class="px-9">
@ -225,6 +222,15 @@
</div> </div>
</div> </div>
<div v-if="numAccounts > 0" class="flex py-2">
Switch Account
<span v-for="accountNum in numAccounts" :key="accountNum">
<button class="text-blue-500 px-2" @click="switchAccount(accountNum)">
#{{ accountNum }}
</button>
</span>
</div>
<div v-bind:class="computedAlertClassNames()"> <div v-bind:class="computedAlertClassNames()">
<button <button
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2" class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
@ -273,11 +279,10 @@ interface RateLimits {
}) })
export default class AccountViewView extends Vue { export default class AccountViewView extends Vue {
activeDid = ""; activeDid = "";
address = "";
derivationPath = ""; derivationPath = "";
firstName = ""; firstName = "";
lastName = ""; lastName = "";
mnemonic = ""; numAccounts = 0;
publicHex = ""; publicHex = "";
publicBase64 = ""; publicBase64 = "";
limits: RateLimits | null = null; limits: RateLimits | null = null;
@ -300,23 +305,22 @@ export default class AccountViewView extends Vue {
try { try {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
if (settings) { this.activeDid = settings?.activeDid || "";
this.activeDid = settings.activeDid || ""; this.firstName = settings?.firstName || "";
this.firstName = settings.firstName || ""; this.lastName = settings?.lastName || "";
this.lastName = settings.lastName || ""; this.showContactGives = !!settings?.showContactGivesInline;
this.showContactGives = !!settings.showContactGivesInline;
}
await accountsDB.open(); await accountsDB.open();
const numAccounts = await accountsDB.accounts.count(); this.numAccounts = await accountsDB.accounts.count();
if (numAccounts === 0) { if (this.numAccounts === 0) {
let address = ""; // 0x... ETH address, without "did:eth:"
let privateHex = ""; let privateHex = "";
this.mnemonic = generateSeed(); const mnemonic = generateSeed();
[this.address, privateHex, this.publicHex, this.derivationPath] = [address, privateHex, this.publicHex, this.derivationPath] =
deriveAddress(this.mnemonic); deriveAddress(mnemonic);
const newId = newIdentifier( const newId = newIdentifier(
this.address, address,
this.publicHex, this.publicHex,
privateHex, privateHex,
this.derivationPath this.derivationPath
@ -326,7 +330,7 @@ export default class AccountViewView extends Vue {
derivationPath: this.derivationPath, derivationPath: this.derivationPath,
did: newId.did, did: newId.did,
identity: JSON.stringify(newId), identity: JSON.stringify(newId),
mnemonic: this.mnemonic, mnemonic: mnemonic,
publicKeyHex: newId.keys[0].publicKeyHex, publicKeyHex: newId.keys[0].publicKeyHex,
}); });
this.activeDid = newId.did; this.activeDid = newId.did;
@ -335,16 +339,13 @@ export default class AccountViewView extends Vue {
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts); const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "undefined"); const identity = JSON.parse(account?.identity || "undefined");
this.address = identity.did;
this.publicHex = identity.keys[0].publicKeyHex; this.publicHex = identity.keys[0].publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64"); this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
this.derivationPath = identity.keys[0].meta.derivationPath; this.derivationPath = identity.keys[0].meta.derivationPath;
if (settings) {
db.settings.update(MASTER_SETTINGS_KEY, { db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: identity.did, activeDid: identity.did,
}); });
}
} catch (err) { } catch (err) {
this.alertMessage = this.alertMessage =
"Clear your cache and start over (after data backup). See console log for more info."; "Clear your cache and start over (after data backup). See console log for more info.";
@ -358,12 +359,9 @@ export default class AccountViewView extends Vue {
this.showContactGives = !this.showContactGives; this.showContactGives = !this.showContactGives;
try { try {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
if (settings) {
db.settings.update(MASTER_SETTINGS_KEY, { db.settings.update(MASTER_SETTINGS_KEY, {
showContactGivesInline: this.showContactGives, showContactGivesInline: this.showContactGives,
}); });
}
} catch (err) { } catch (err) {
this.alertMessage = this.alertMessage =
"Clear your cache and start over (after data backup). See console log for more info."; "Clear your cache and start over (after data backup). See console log for more info.";
@ -401,7 +399,7 @@ export default class AccountViewView extends Vue {
const url = endorserApiServer + "/api/report/rateLimits"; const url = endorserApiServer + "/api/report/rateLimits";
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.address, accounts); const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "undefined"); const identity = JSON.parse(account?.identity || "undefined");
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
@ -432,6 +430,22 @@ export default class AccountViewView extends Vue {
} }
} }
async switchAccount(accountNum: number) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = accounts[accountNum - 1];
await db.open();
db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: account.did,
});
this.activeDid = account.did;
this.derivationPath = account.derivationPath;
this.publicHex = account.publicKeyHex;
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
}
public showContactGivesClassNames() { public showContactGivesClassNames() {
return { return {
"bg-slate-900": !this.showContactGives, "bg-slate-900": !this.showContactGives,

2
src/views/ContactAmountsView.vue

@ -25,7 +25,7 @@
></router-link> ></router-link>
</li> </li>
<!-- Contacts --> <!-- Contacts -->
<li class="basis-1/5 rounded-md text-slate-400"> <li class="basis-1/5 rounded-md text-slate-500">
<router-link <router-link
:to="{ name: 'contacts' }" :to="{ name: 'contacts' }"
class="block text-center py-3 px-1" class="block text-center py-3 px-1"

6
src/views/ImportAccountView.vue

@ -77,8 +77,6 @@ export default class ImportAccountView extends Vue {
try { try {
await accountsDB.open(); await accountsDB.open();
const num_accounts = await accountsDB.accounts.count();
if (num_accounts === 0) {
await accountsDB.accounts.add({ await accountsDB.accounts.add({
dateCreated: new Date().toISOString(), dateCreated: new Date().toISOString(),
derivationPath: this.derivationPath, derivationPath: this.derivationPath,
@ -87,16 +85,12 @@ export default class ImportAccountView extends Vue {
mnemonic: mne, mnemonic: mne,
publicKeyHex: newId.keys[0].publicKeyHex, publicKeyHex: newId.keys[0].publicKeyHex,
}); });
}
// record that as the active DID // record that as the active DID
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
if (settings) {
db.settings.update(MASTER_SETTINGS_KEY, { db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: newId.did, activeDid: newId.did,
}); });
}
this.$router.push({ name: "account" }); this.$router.push({ name: "account" });
} catch (err) { } catch (err) {
console.log("Error!"); console.log("Error!");

6
src/views/NewEditAccountView.vue

@ -70,10 +70,8 @@ export default class NewEditAccountView extends Vue {
async created() { async created() {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
if (settings) { this.firstName = settings?.firstName || "";
this.firstName = settings.firstName || ""; this.lastName = settings?.lastName || "";
this.lastName = settings.lastName || "";
}
} }
onClickSaveChanges() { onClickSaveChanges() {

Loading…
Cancel
Save