forked from jsnbuchanan/crowd-funder-for-time-pwa
allow to switch between accounts
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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);
|
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||||
if (settings) {
|
showContactGivesInline: this.showContactGives,
|
||||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
});
|
||||||
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,
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -77,26 +77,20 @@ export default class ImportAccountView extends Vue {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await accountsDB.open();
|
await accountsDB.open();
|
||||||
const num_accounts = await accountsDB.accounts.count();
|
await accountsDB.accounts.add({
|
||||||
if (num_accounts === 0) {
|
dateCreated: new Date().toISOString(),
|
||||||
await accountsDB.accounts.add({
|
derivationPath: this.derivationPath,
|
||||||
dateCreated: new Date().toISOString(),
|
did: newId.did,
|
||||||
derivationPath: this.derivationPath,
|
identity: JSON.stringify(newId),
|
||||||
did: newId.did,
|
mnemonic: mne,
|
||||||
identity: JSON.stringify(newId),
|
publicKeyHex: newId.keys[0].publicKeyHex,
|
||||||
mnemonic: mne,
|
});
|
||||||
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);
|
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||||
if (settings) {
|
activeDid: newId.did,
|
||||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
});
|
||||||
activeDid: newId.did,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.$router.push({ name: "account" });
|
this.$router.push({ name: "account" });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error!");
|
console.log("Error!");
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user