forked from jsnbuchanan/crowd-funder-for-time-pwa
add registration check and the ability to register someone
This commit is contained in:
@@ -202,6 +202,29 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<button
|
||||
class="text-center text-md text-blue-500 px-1.5 py-2"
|
||||
@click="checkLimits()"
|
||||
>
|
||||
Check Limits
|
||||
</button>
|
||||
<div v-if="!!limits?.nextWeekBeginDateTime" class="px-9">
|
||||
<span class="font-bold">Rate Limits</span>
|
||||
<p>
|
||||
You have done {{ limits.doneClaimsThisWeek }} claims out of
|
||||
{{ limits.maxClaimsPerWeek }} for this week. Your claims counter
|
||||
resets at {{ readableTime(limits.nextWeekBeginDateTime) }}
|
||||
</p>
|
||||
<p>
|
||||
You have done {{ limits.doneRegistrationsThisMonth }} registrations
|
||||
out of {{ limits.maxRegistrationsPerMonth }} for this month. Your
|
||||
registrations counter resets at
|
||||
{{ readableTime(limits.nextMonthBeginDateTime) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-bind:class="computedAlertClassNames()">
|
||||
<button
|
||||
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
|
||||
@@ -221,27 +244,47 @@ import { Options, Vue } from "vue-class-component";
|
||||
import { useClipboard } from "@vueuse/core";
|
||||
import { db, accountsDB } from "@/db";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
|
||||
import {
|
||||
accessToken,
|
||||
deriveAddress,
|
||||
generateSeed,
|
||||
newIdentifier,
|
||||
} from "@/libs/crypto";
|
||||
import { AppString } from "@/constants/app";
|
||||
//import { testServerRegisterUser } from "../test";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const Buffer = require("buffer/").Buffer;
|
||||
|
||||
interface RateLimits {
|
||||
doneClaimsThisWeek: string;
|
||||
doneRegistrationsThisMonth: string;
|
||||
maxClaimsPerWeek: string;
|
||||
maxRegistrationsPerMonth: string;
|
||||
nextMonthBeginDateTime: string;
|
||||
nextWeekBeginDateTime: string;
|
||||
}
|
||||
|
||||
@Options({
|
||||
components: {},
|
||||
})
|
||||
export default class AccountViewView extends Vue {
|
||||
address = "";
|
||||
derivationPath = "";
|
||||
firstName = "";
|
||||
lastName = "";
|
||||
mnemonic = "";
|
||||
publicHex = "";
|
||||
publicBase64 = "";
|
||||
derivationPath = "";
|
||||
limits: RateLimits | null = null;
|
||||
showContactGives = false;
|
||||
|
||||
copy = useClipboard().copy;
|
||||
|
||||
readableTime(timeStr: string) {
|
||||
return timeStr.substring(0, timeStr.indexOf("T"));
|
||||
}
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
// Uncomment to register this user on the test server.
|
||||
@@ -346,6 +389,39 @@ export default class AccountViewView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
async checkLimits() {
|
||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
||||
const url = endorserApiServer + "/api/report/rateLimits";
|
||||
await accountsDB.open();
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const identity = JSON.parse(accounts[0].identity);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
|
||||
try {
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
if (resp.status === 200) {
|
||||
this.limits = resp.data;
|
||||
} else {
|
||||
this.alertTitle = "Error from Server";
|
||||
console.log("Bad response retrieving limits: ", resp.data);
|
||||
if (resp.data.error?.message) {
|
||||
this.alertMessage = resp.data.error?.message;
|
||||
} else {
|
||||
this.alertMessage = "Bad server response of " + resp.status;
|
||||
}
|
||||
this.isAlertVisible = true;
|
||||
}
|
||||
} catch (err) {
|
||||
this.alertTitle = "Error from Server";
|
||||
this.alertMessage = err as string;
|
||||
this.isAlertVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
alertMessage = "";
|
||||
alertTitle = "";
|
||||
isAlertVisible = false;
|
||||
|
||||
Reference in New Issue
Block a user