Files
app.zeusln.zeus/stores/MessageSignStore.ts
T
2021-11-04 00:02:58 -04:00

35 lines
979 B
TypeScript

import { action, observable } from 'mobx';
import RESTUtils from './../utils/RESTUtils';
import Base64Utils from './../utils/Base64Utils';
export default class MessageSignStore {
@observable public loading = false;
@observable public error = false;
@observable public signature: string | null;
resetSignature() {
this.signature = null;
this.error = false;
}
@action
public signMessage = (text: string) => {
this.loading = true;
const body = Base64Utils.btoa(text);
RESTUtils.signMessage(body)
.then((data: any) => {
// TODO: properly decode signature
this.signature = data.signature;
this.error = false;
})
.catch((error: any) => {
this.error = error.toString();
this.resetSignature;
})
.finally(() => {
this.loading = false;
});
};
}