Browse Source

allow to switch the server

pull/19/head
Trent Larson 2 years ago
parent
commit
fc7c1187e8
  1. 1
      project.yaml
  2. 11
      src/constants/app.ts
  3. 6
      src/db/index.ts
  4. 1
      src/db/tables/settings.ts
  5. 2
      src/main.ts
  6. 3
      src/test/index.ts
  7. 55
      src/views/AccountViewView.vue
  8. 11
      src/views/ContactAmountsView.vue
  9. 24
      src/views/ContactsView.vue
  10. 8
      src/views/NewEditProjectView.vue
  11. 9
      src/views/ProjectViewView.vue
  12. 5
      src/views/ProjectsView.vue

1
project.yaml

@ -7,7 +7,6 @@
- contacts v1 : - contacts v1 :
- .1 remove 'copy' until it works - .1 remove 'copy' until it works
- .5 switch to prod server
- .5 Add page to show seed. - .5 Add page to show seed.
- 01 Provide a way to import the non-sensitive data. - 01 Provide a way to import the non-sensitive data.
- 01 Provide way to share your contact info. - 01 Provide way to share your contact info.

11
src/constants/app.ts

@ -2,8 +2,11 @@
* Generic strings that could be used throughout the app. * Generic strings that could be used throughout the app.
*/ */
export enum AppString { export enum AppString {
APP_NAME = "KickStart with Time", APP_NAME = "Kick-Start with Time",
VERSION = "0.1",
DEFAULT_ENDORSER_API_SERVER = "https://test.endorser.ch:8000", PROD_ENDORSER_API_SERVER = "https://endorser.ch:3000",
//DEFAULT_ENDORSER_API_SERVER = "http://localhost:3000", TEST_ENDORSER_API_SERVER = "https://test.endorser.ch:8000",
LOCAL_ENDORSER_API_SERVER = "http://localhost:3000",
DEFAULT_ENDORSER_API_SERVER = TEST_ENDORSER_API_SERVER,
} }

6
src/db/index.ts

@ -7,6 +7,7 @@ import {
Settings, Settings,
SettingsSchema, SettingsSchema,
} from "./tables/settings"; } from "./tables/settings";
import { AppString } from "@/constants/app";
// a separate DB because the seed is super-sensitive data // a separate DB because the seed is super-sensitive data
type SensitiveTables = { type SensitiveTables = {
@ -57,5 +58,8 @@ db.version(1).stores(NonsensitiveSchemas);
// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event // initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event
db.on("populate", function () { db.on("populate", function () {
// ensure there's an initial entry for settings // ensure there's an initial entry for settings
db.settings.add({ id: MASTER_SETTINGS_KEY }); db.settings.add({
id: MASTER_SETTINGS_KEY,
apiServer: AppString.DEFAULT_ENDORSER_API_SERVER,
});
}); });

1
src/db/tables/settings.ts

@ -2,6 +2,7 @@
export type Settings = { export type Settings = {
id: number; // there's only one entry: MASTER_SETTINGS_KEY id: number; // there's only one entry: MASTER_SETTINGS_KEY
activeDid?: string; activeDid?: string;
apiServer?: string;
firstName?: string; firstName?: string;
lastName?: string; lastName?: string;
showContactGivesInline?: boolean; showContactGivesInline?: boolean;

2
src/main.ts

@ -21,6 +21,7 @@ import {
faEye, faEye,
faEyeSlash, faEyeSlash,
faFileLines, faFileLines,
faFloppyDisk,
faFolderOpen, faFolderOpen,
faHand, faHand,
faHouseChimney, faHouseChimney,
@ -53,6 +54,7 @@ library.add(
faEye, faEye,
faEyeSlash, faEyeSlash,
faFileLines, faFileLines,
faFloppyDisk,
faFolderOpen, faFolderOpen,
faHand, faHand,
faHouseChimney, faHouseChimney,

3
src/test/index.ts

@ -49,7 +49,8 @@ export async function testServerRegisterUser() {
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const endorserApiServer =
settings?.apiServer || AppString.TEST_ENDORSER_API_SERVER;
const url = endorserApiServer + "/api/claim"; const url = endorserApiServer + "/api/claim";
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",

55
src/views/AccountViewView.vue

@ -248,6 +248,40 @@
</div> </div>
</div> </div>
<div class="flex py-2">
Claim Server
<input
type="text"
class="block w-full rounded border border-slate-400 px-3 py-2"
v-model="apiServerInput"
/>
<button
v-if="apiServerInput != apiServer"
class="px-4 rounded bg-slate-200 border border-slate-400"
@click="onClickSaveApiServer()"
>
<fa icon="floppy-disk" class="fa-fw"></fa>
</button>
<button
class="px-4 rounded bg-slate-200 border border-slate-400"
@click="setApiServerInput(Constants.PROD_ENDORSER_API_SERVER)"
>
Use Prod
</button>
<button
class="px-4 rounded bg-slate-200 border border-slate-400"
@click="setApiServerInput(Constants.TEST_ENDORSER_API_SERVER)"
>
Use Test
</button>
<button
class="px-4 rounded bg-slate-200 border border-slate-400"
@click="setApiServerInput(Constants.LOCAL_ENDORSER_API_SERVER)"
>
Use Local
</button>
</div>
<div v-if="numAccounts > 0" class="flex py-2"> <div v-if="numAccounts > 0" class="flex py-2">
Switch Account Switch Account
<span v-for="accountNum in numAccounts" :key="accountNum"> <span v-for="accountNum in numAccounts" :key="accountNum">
@ -302,7 +336,11 @@ interface RateLimits {
@Component @Component
export default class AccountViewView extends Vue { export default class AccountViewView extends Vue {
Constants = AppString;
activeDid = ""; activeDid = "";
apiServer = "";
apiServerInput = "";
derivationPath = ""; derivationPath = "";
firstName = ""; firstName = "";
lastName = ""; lastName = "";
@ -345,6 +383,8 @@ export default class AccountViewView extends Vue {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
this.apiServerInput = settings?.apiServer || "";
this.firstName = settings?.firstName || ""; this.firstName = settings?.firstName || "";
this.lastName = settings?.lastName || ""; this.lastName = settings?.lastName || "";
this.showContactGives = !!settings?.showContactGivesInline; this.showContactGives = !!settings?.showContactGivesInline;
@ -433,8 +473,7 @@ export default class AccountViewView extends Vue {
} }
async checkLimits() { async checkLimits() {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/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.activeDid, accounts); const account = R.find((acc) => acc.did === this.activeDid, accounts);
@ -491,6 +530,18 @@ export default class AccountViewView extends Vue {
}; };
} }
async onClickSaveApiServer() {
await db.open();
db.settings.update(MASTER_SETTINGS_KEY, {
apiServer: this.apiServerInput,
});
this.apiServer = this.apiServerInput;
}
setApiServerInput(value) {
this.apiServerInput = value;
}
alertMessage = ""; alertMessage = "";
alertTitle = ""; alertTitle = "";
isAlertVisible = false; isAlertVisible = false;

11
src/views/ContactAmountsView.vue

@ -144,6 +144,7 @@ import { AxiosError } from "axios";
@Options({}) @Options({})
export default class ContactsView extends Vue { export default class ContactsView extends Vue {
activeDid = ""; activeDid = "";
apiServer = "";
contact: Contact | null = null; contact: Contact | null = null;
giveRecords: Array<GiveServerRecord> = []; giveRecords: Array<GiveServerRecord> = [];
@ -155,6 +156,7 @@ export default class ContactsView extends Vue {
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
if (this.activeDid && this.contact) { if (this.activeDid && this.contact) {
this.loadGives(this.activeDid, this.contact); this.loadGives(this.activeDid, this.contact);
@ -168,14 +170,12 @@ export default class ContactsView extends Vue {
const account = R.find((acc) => acc.did === activeDid, accounts); const account = R.find((acc) => acc.did === activeDid, accounts);
const identity = JSON.parse(account?.identity || "undefined"); const identity = JSON.parse(account?.identity || "undefined");
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
// load all the time I have given to them // load all the time I have given to them
try { try {
let result = []; let result = [];
const url = const url =
endorserApiServer + this.apiServer +
"/api/v2/report/gives?agentDid=" + "/api/v2/report/gives?agentDid=" +
encodeURIComponent(identity.did) + encodeURIComponent(identity.did) +
"&recipientDid=" + "&recipientDid=" +
@ -201,7 +201,7 @@ export default class ContactsView extends Vue {
} }
const url2 = const url2 =
endorserApiServer + this.apiServer +
"/api/v2/report/gives?agentDid=" + "/api/v2/report/gives?agentDid=" +
encodeURIComponent(contact.did) + encodeURIComponent(contact.did) +
"&recipientDid=" + "&recipientDid=" +
@ -282,8 +282,7 @@ export default class ContactsView extends Vue {
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/api/v2/claim";
const url = endorserApiServer + "/api/v2/claim";
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",

24
src/views/ContactsView.vue

@ -271,6 +271,7 @@ const Buffer = require("buffer/").Buffer;
}) })
export default class ContactsView extends Vue { export default class ContactsView extends Vue {
activeDid = ""; activeDid = "";
apiServer = "";
contacts: Array<Contact> = []; contacts: Array<Contact> = [];
contactInput = ""; contactInput = "";
// { "did:...": concatenated-descriptions } entry for each contact // { "did:...": concatenated-descriptions } entry for each contact
@ -296,6 +297,7 @@ export default class ContactsView extends Vue {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
this.showGiveNumbers = !!settings?.showContactGivesInline; this.showGiveNumbers = !!settings?.showContactGivesInline;
if (this.showGiveNumbers) { if (this.showGiveNumbers) {
@ -321,12 +323,10 @@ export default class ContactsView extends Vue {
return; return;
} }
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
// load all the time I have given // load all the time I have given
try { try {
const url = const url =
endorserApiServer + this.apiServer +
"/api/v2/report/gives?agentDid=" + "/api/v2/report/gives?agentDid=" +
encodeURIComponent(identity.did); encodeURIComponent(identity.did);
const token = await accessToken(identity); const token = await accessToken(identity);
@ -335,7 +335,7 @@ export default class ContactsView extends Vue {
Authorization: "Bearer " + token, Authorization: "Bearer " + token,
}; };
const resp = await this.axios.get(url, { headers }); const resp = await this.axios.get(url, { headers });
console.log("All gifts you've given:", resp.data); //console.log("All gifts you've given:", resp.data);
if (resp.status === 200) { if (resp.status === 200) {
const contactDescriptions: Record<string, string> = {}; const contactDescriptions: Record<string, string> = {};
const contactConfirmed: Record<string, number> = {}; const contactConfirmed: Record<string, number> = {};
@ -381,7 +381,7 @@ export default class ContactsView extends Vue {
// load all the time I have received // load all the time I have received
try { try {
const url = const url =
endorserApiServer + this.apiServer +
"/api/v2/report/gives?recipientDid=" + "/api/v2/report/gives?recipientDid=" +
encodeURIComponent(identity.did); encodeURIComponent(identity.did);
const token = await accessToken(identity); const token = await accessToken(identity);
@ -390,7 +390,7 @@ export default class ContactsView extends Vue {
Authorization: "Bearer " + token, Authorization: "Bearer " + token,
}; };
const resp = await this.axios.get(url, { headers }); const resp = await this.axios.get(url, { headers });
console.log("All gifts you've recieved:", resp.data); //console.log("All gifts you've recieved:", resp.data);
if (resp.status === 200) { if (resp.status === 200) {
const contactDescriptions: Record<string, string> = {}; const contactDescriptions: Record<string, string> = {};
const contactConfirmed: Record<string, number> = {}; const contactConfirmed: Record<string, number> = {};
@ -520,8 +520,7 @@ export default class ContactsView extends Vue {
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/api/v2/claim";
const url = endorserApiServer + "/api/v2/claim";
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -561,9 +560,8 @@ export default class ContactsView extends Vue {
} }
async setVisibility(contact: Contact, visibility: boolean) { async setVisibility(contact: Contact, visibility: boolean) {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = const url =
endorserApiServer + this.apiServer +
"/api/report/" + "/api/report/" +
(visibility ? "canSeeMe" : "cannotSeeMe"); (visibility ? "canSeeMe" : "cannotSeeMe");
await accountsDB.open(); await accountsDB.open();
@ -601,9 +599,8 @@ export default class ContactsView extends Vue {
} }
async checkVisibility(contact: Contact) { async checkVisibility(contact: Contact) {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = const url =
endorserApiServer + this.apiServer +
"/api/report/canDidExplicitlySeeMe?did=" + "/api/report/canDidExplicitlySeeMe?did=" +
encodeURIComponent(contact.did); encodeURIComponent(contact.did);
await accountsDB.open(); await accountsDB.open();
@ -774,8 +771,7 @@ export default class ContactsView extends Vue {
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/api/v2/claim";
const url = endorserApiServer + "/api/v2/claim";
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",

8
src/views/NewEditProjectView.vue

@ -101,6 +101,7 @@ interface VerifiableCredential {
}) })
export default class NewEditProjectView extends Vue { export default class NewEditProjectView extends Vue {
activeDid = ""; activeDid = "";
apiServer = "";
projectName = ""; projectName = "";
description = ""; description = "";
errorMessage = ""; errorMessage = "";
@ -116,6 +117,7 @@ export default class NewEditProjectView extends Vue {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
if (this.projectId) { if (this.projectId) {
await accountsDB.open(); await accountsDB.open();
@ -132,9 +134,8 @@ export default class NewEditProjectView extends Vue {
} }
async LoadProject(identity: IIdentifier) { async LoadProject(identity: IIdentifier) {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = const url =
endorserApiServer + this.apiServer +
"/api/claim/byHandle/" + "/api/claim/byHandle/" +
encodeURIComponent(this.projectId); encodeURIComponent(this.projectId);
const token = await accessToken(identity); const token = await accessToken(identity);
@ -191,8 +192,7 @@ export default class NewEditProjectView extends Vue {
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/api/v2/claim";
const url = endorserApiServer + "/api/v2/claim";
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",

9
src/views/ProjectViewView.vue

@ -161,6 +161,7 @@ import { IIdentifier } from "@veramo/core";
components: {}, components: {},
}) })
export default class ProjectViewView extends Vue { export default class ProjectViewView extends Vue {
apiServer = "";
expanded = false; expanded = false;
name = ""; name = "";
description = ""; description = "";
@ -188,9 +189,10 @@ export default class ProjectViewView extends Vue {
} }
async LoadProject(identity: IIdentifier) { async LoadProject(identity: IIdentifier) {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url =
// eslint-disable-next-line prettier/prettier this.apiServer +
const url = endorserApiServer + "/api/claim/byHandle/" + encodeURIComponent(this.projectId); "/api/claim/byHandle/" +
encodeURIComponent(this.projectId);
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -232,6 +234,7 @@ export default class ProjectViewView extends Vue {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
const activeDid = settings?.activeDid || ""; const activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
await accountsDB.open(); await accountsDB.open();
const num_accounts = await accountsDB.accounts.count(); const num_accounts = await accountsDB.accounts.count();

5
src/views/ProjectsView.vue

@ -114,6 +114,7 @@ import { IIdentifier } from "@veramo/core";
components: {}, components: {},
}) })
export default class ProjectsView extends Vue { export default class ProjectsView extends Vue {
apiServer = "";
projects: { handleId: string; name: string; description: string }[] = []; projects: { handleId: string; name: string; description: string }[] = [];
onClickLoadProject(id: string) { onClickLoadProject(id: string) {
@ -127,8 +128,7 @@ export default class ProjectsView extends Vue {
} }
async LoadProjects(identity: IIdentifier) { async LoadProjects(identity: IIdentifier) {
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = this.apiServer + "/api/v2/report/plansByIssuer";
const url = endorserApiServer + "/api/v2/report/plansByIssuer";
const token = await accessToken(identity); const token = await accessToken(identity);
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -161,6 +161,7 @@ export default class ProjectsView extends Vue {
await db.open(); await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await db.settings.get(MASTER_SETTINGS_KEY);
const activeDid = settings?.activeDid || ""; const activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
await accountsDB.open(); await accountsDB.open();
const num_accounts = await accountsDB.accounts.count(); const num_accounts = await accountsDB.accounts.count();

Loading…
Cancel
Save