forked from trent_larson/crowd-funder-for-time-pwa
fix error setting the apiServer to "", plus some refactors while fixing test 40
This commit is contained in:
@@ -78,7 +78,7 @@ db.version(4)
|
||||
});
|
||||
});
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
const DEFAULT_SETTINGS: Settings = {
|
||||
id: MASTER_SETTINGS_KEY,
|
||||
activeDid: undefined,
|
||||
apiServer: DEFAULT_ENDORSER_API_SERVER,
|
||||
@@ -183,42 +183,34 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
|
||||
}
|
||||
}
|
||||
|
||||
// Update settings for the given account, or in MASTER_SETTINGS_KEY if no accountDid is provided.
|
||||
// Don't expose this because we should be explicit on whether we're updating the default settings or account settings.
|
||||
async function updateSettings(settingsChanges: Settings): Promise<void> {
|
||||
await db.open();
|
||||
if (!settingsChanges.accountDid) {
|
||||
// ensure there is no "id" that would override the key
|
||||
delete settingsChanges.id;
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
|
||||
} else {
|
||||
const result = await db.settings
|
||||
.where("accountDid")
|
||||
.equals(settingsChanges.accountDid)
|
||||
.modify(settingsChanges);
|
||||
if (result === 0) {
|
||||
if (!settingsChanges.id) {
|
||||
// It is unfortunate that we have to set this explicitly.
|
||||
// We didn't make id a "++id" at the beginning and Dexie won't let us change it,
|
||||
// plus we made our first settings objects MASTER_SETTINGS_KEY = 1 instead of 0
|
||||
settingsChanges.id = (await db.settings.count()) + 1;
|
||||
}
|
||||
await db.settings.add(settingsChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateDefaultSettings(settings: Settings): Promise<void> {
|
||||
delete settings.accountDid; // just in case
|
||||
await updateSettings(settings);
|
||||
export async function updateDefaultSettings(
|
||||
settingsChanges: Settings,
|
||||
): Promise<void> {
|
||||
delete settingsChanges.accountDid; // just in case
|
||||
// ensure there is no "id" that would override the key
|
||||
delete settingsChanges.id;
|
||||
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
|
||||
}
|
||||
|
||||
export async function updateAccountSettings(
|
||||
accountDid: string,
|
||||
settings: Settings,
|
||||
settingsChanges: Settings,
|
||||
): Promise<void> {
|
||||
settings.accountDid = accountDid;
|
||||
await updateSettings(settings);
|
||||
settingsChanges.accountDid = accountDid;
|
||||
delete settingsChanges.id; // key off account, not ID
|
||||
const result = await db.settings
|
||||
.where("accountDid")
|
||||
.equals(settingsChanges.accountDid)
|
||||
.modify(settingsChanges);
|
||||
if (result === 0) {
|
||||
if (!settingsChanges.id) {
|
||||
// It is unfortunate that we have to set this explicitly.
|
||||
// We didn't make id a "++id" at the beginning and Dexie won't let us change it,
|
||||
// plus we made our first settings objects MASTER_SETTINGS_KEY = 1 instead of 0
|
||||
settingsChanges.id = (await db.settings.count()) + 1;
|
||||
}
|
||||
await db.settings.add(settingsChanges);
|
||||
}
|
||||
}
|
||||
|
||||
// similar method is in the sw_scripts/additional-scripts.js file
|
||||
|
||||
@@ -610,7 +610,7 @@ export default class Help extends Vue {
|
||||
async unsetFinishedOnboarding() {
|
||||
const settings = await retrieveSettingsForActiveAccount();
|
||||
if (settings.activeDid) {
|
||||
await updateAccountSettings(settings.activeDid || "", {
|
||||
await updateAccountSettings(settings.activeDid, {
|
||||
finishedOnboarding: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -539,7 +539,6 @@ export default class HomeView extends Vue {
|
||||
if (resp.status === 200) {
|
||||
await updateAccountSettings(this.activeDid, {
|
||||
isRegistered: true,
|
||||
apiServer: "",
|
||||
});
|
||||
this.isRegistered = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user