made userDataStore

This commit is contained in:
Daria Golova
2022-06-29 18:34:42 +03:00
parent bcfc018560
commit 1c539e5255
3 changed files with 56 additions and 7 deletions

View File

@@ -10,6 +10,8 @@ class Store {
_nodeInfo = {}
_userData = {}
constructor() {
makeAutoObservable(this);
@@ -18,15 +20,18 @@ class Store {
reaction(() => this.tokenKey, () => fetchWrapper.getAuth('http://3.125.47.101/api/data/account', {
networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID
}))
}).then((res) => this.userInfoFetchChange(res)))
};
fetchCreateNewAccount() {
fetchWrapper.postAuth('http://3.125.47.101/api/data/account', {
networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID
}, [...this.encryptAccountData])
.catch(()=>{})
}, [...this.encryptAccountData]).catch(()=>{})
};
userInfoFetchChange(res) {
this._userData = res;
}
savePassPhrase(phrase) {
@@ -51,6 +56,10 @@ class Store {
console.log(err)
}
get userData() {
return this._userData;
}
get passPhrase() {
return 'rocket north inform swift improve fringe sweet crew client canyon bean autumn'
}

View File

@@ -0,0 +1,24 @@
import { cryptography } from "@liskhq/lisk-client";
import { makeAutoObservable, reaction } from "mobx";
import { registrationStore } from './store';
class UserDataStore{
_data = []
constructor() {
makeAutoObservable(this);
reaction(() => ({data: registrationStore.userData}), ({data}) => {
this._data = data.data;
})
}
get userData(){
return this._data.map((elem) => ({
...elem,
value: cryptography.decryptMessageWithPassphrase(elem.value, elem.value_nonce, registrationStore.passPhrase, registrationStore.pubKey)
}))
}
}
export const userDataStore = new UserDataStore();