clear-wallet/src/views/SignMessage.vue

157 lines
3.5 KiB
Vue
Raw Normal View History

2022-10-07 17:07:59 +00:00
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Sign Message</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-item>
<ion-label>Message to Sign</ion-label>
</ion-item>
<ion-item>
<ion-text>{{ signMsg }}</ion-text>
</ion-item>
<ion-item>
<ion-button @click="onCancel">Cancel</ion-button>
<ion-button @click="onSign">Sign</ion-button>
</ion-item>
2022-10-10 00:52:23 +00:00
<ion-item>Auto-reject Timer: {{ timerReject }}</ion-item>
2022-10-07 17:07:59 +00:00
<ion-alert
:is-open="alertOpen"
header="Error"
:message="alertMsg"
:buttons="['OK']"
@didDismiss="alertOpen = false"
></ion-alert>
<ion-loading
:is-open="loading"
cssClass="my-custom-class"
message="Please wait..."
:duration="4000"
@didDismiss="loading = false"
/>
</ion-content>
</ion-page>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
import {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonItem,
IonLabel,
IonButton,
IonAlert,
IonText,
IonLoading,
2022-10-10 00:52:23 +00:00
modalController,
2022-10-10 23:01:14 +00:00
onIonViewWillEnter,
2022-10-07 17:07:59 +00:00
} from "@ionic/vue";
// import { ethers } from "ethers";
2022-10-10 23:01:14 +00:00
import { hexTostr } from "@/utils/platform";
2022-10-10 00:52:23 +00:00
import { approve, walletPing } from "@/extension/userRequest";
2022-10-10 23:01:14 +00:00
import { useRoute } from "vue-router";
2022-10-16 22:25:20 +00:00
import { getSelectedAccount, unBlockLockout, blockLockout } from "@/utils/platform";
2022-10-10 23:01:14 +00:00
import UnlockModal from "@/views/UnlockModal.vue";
2022-10-07 17:07:59 +00:00
export default defineComponent({
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonItem,
IonLabel,
IonButton,
IonAlert,
IonText,
2022-10-10 23:01:14 +00:00
IonLoading,
2022-10-07 17:07:59 +00:00
},
setup: () => {
2022-10-10 23:01:14 +00:00
const route = useRoute();
const loading = ref(false);
const rid = (route?.params?.rid as string) ?? "";
const signMsg = ref(hexTostr(hexTostr((route?.params?.param as string) ?? "")));
2022-10-07 17:07:59 +00:00
const alertOpen = ref(false);
const alertMsg = ref("");
2022-10-10 00:52:23 +00:00
const timerReject = ref(140);
2022-10-10 23:01:14 +00:00
let interval: any;
2022-10-07 17:07:59 +00:00
const onCancel = () => {
2022-10-10 00:52:23 +00:00
window.close();
2022-10-10 23:01:14 +00:00
if (interval) {
2022-10-10 00:52:23 +00:00
try {
2022-10-10 23:01:14 +00:00
unBlockLockout();
clearInterval(interval);
2022-10-10 00:52:23 +00:00
} catch {
// ignore
}
}
2022-10-07 17:07:59 +00:00
};
2022-10-10 00:52:23 +00:00
onIonViewWillEnter(async () => {
2022-10-10 23:01:14 +00:00
blockLockout();
2022-10-10 00:52:23 +00:00
interval = setInterval(async () => {
2022-10-10 23:01:14 +00:00
if (timerReject.value <= 0) {
onCancel();
2022-10-10 00:52:23 +00:00
return;
}
2022-10-10 23:01:14 +00:00
timerReject.value -= 1;
walletPing();
}, 1000) as any;
2022-10-10 00:52:23 +00:00
});
2022-10-07 17:07:59 +00:00
const openModal = async () => {
2022-10-10 23:01:14 +00:00
const modal = await modalController.create({
component: UnlockModal,
componentProps: {
unlockType: "message",
},
});
modal.present();
const { role } = await modal.onWillDismiss();
if (role === "confirm") return true;
return false;
};
2022-10-07 17:07:59 +00:00
const onSign = async () => {
2022-10-10 23:01:14 +00:00
loading.value = true;
const selectedAccount = await getSelectedAccount();
2022-10-16 22:25:20 +00:00
loading.value = false;
2022-10-10 23:01:14 +00:00
if ((selectedAccount.pk ?? "").length !== 66) {
const modalResult = await openModal();
if (modalResult) {
unBlockLockout();
loading.value = true;
2022-10-10 23:01:14 +00:00
approve(rid);
} else {
onCancel();
2022-10-07 17:07:59 +00:00
}
2022-10-10 23:01:14 +00:00
} else {
unBlockLockout();
approve(rid);
}
loading.value = false;
};
2022-10-07 17:07:59 +00:00
return {
signMsg,
onCancel,
alertOpen,
alertMsg,
onSign,
2022-10-10 00:52:23 +00:00
loading,
2022-10-10 23:01:14 +00:00
timerReject,
2022-10-07 17:07:59 +00:00
};
},
});
</script>