Merge branch 'master' into DID-13

This commit is contained in:
DuCay
2022-08-24 17:21:00 +03:00
committed by GitHub
5 changed files with 262 additions and 172 deletions

View File

@@ -166,7 +166,6 @@ const Profile = observer (() => {
}; };
const addDataParameters = () => { const addDataParameters = () => {
console.log(addedValues)
const label = addedValues.label.toLowerCase().split(' ').join(''); const label = addedValues.label.toLowerCase().split(' ').join('');
if(labelMap[label]) if(labelMap[label])
addedValues.key = addedValues.label.toLowerCase().split(' ').join(''); addedValues.key = addedValues.label.toLowerCase().split(' ').join('');

View File

@@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import {statusMap} from "../../shared/statusMap"; import { statusMap } from '../../shared/statusMap';
function ProfileTableItem(props) { function ProfileTableItem(props) {
const [descriptionOpen, setDescriptionOpen] = useState(false); const [descriptionOpen, setDescriptionOpen] = useState(false);
@@ -11,7 +11,13 @@ function ProfileTableItem(props) {
<div className="flex items-center"> <div className="flex items-center">
<label className="inline-flex"> <label className="inline-flex">
<span className="sr-only">Select</span> <span className="sr-only">Select</span>
<input id={props.id} className="form-checkbox" type="checkbox" onChange={props.handleClick} checked={props.isChecked} /> <input
id={props.id}
className="form-checkbox"
type="checkbox"
onChange={props.handleClick}
checked={props.isChecked}
/>
</label> </label>
</div> </div>
</td> </td>
@@ -21,44 +27,50 @@ function ProfileTableItem(props) {
<img className="rounded-full" src={props.image} width="40" height="40" alt={props.property} /> <img className="rounded-full" src={props.image} width="40" height="40" alt={props.property} />
</div> </div>
<div className="flex flex-col w-60"> <div className="flex flex-col w-60">
<div className="font-semibold text-slate-800 text-base">{props.status===statusMap.blockchained?`${props.value.slice(0,4)}****${props.value.slice(props.value.length-4)}`:props.value}</div> <div className="font-semibold text-slate-800 text-base">
{props.status === 'Blockchained' || props.status === statusMap.processed
? `${props.value.slice(0, 4)}****${props.value.slice(props.value.length - 4)}`
: props.value}
</div>
<div className="font-normal text-xxs">{props.property}</div> <div className="font-normal text-xxs">{props.property}</div>
</div> </div>
</div> </div>
</td> </td>
<td className="py-3 whitespace-nowrap w-px px-2.5 text-left min-w-[117px]"> <td className="py-3 whitespace-nowrap w-px">
<div className="w-fit text-xs inline-flex font-medium py-1"> <div className="w-fit text-xs inline-flex font-medium px-2.5 py-1">
{(props.status === statusMap.blockchained) ? ( {props.status === statusMap.blockchained ? (
<div className="bg-amber-100 text-amber-600 rounded-full text-center px-2.5 py-1"> <div className="bg-amber-100 text-amber-600 rounded-full text-center px-2.5 py-1">{props.status}</div>
{props.status} ) : props.status === statusMap.processed ? (
</div>) : <div className="bg-amber-100 text-amber-600 rounded-full text-center px-2.5 py-1">{props.status}</div>
(props.status === statusMap.stored) ? ( ) : props.status === statusMap.stored ? (
<div className="bg-slate-700 text-slate-100 rounded-full text-center px-2.5 py-1"> <div className="bg-slate-700 text-slate-100 rounded-full text-center px-2.5 py-1">{props.status}</div>
{props.status} ) : props.status === statusMap.completed ? (
</div>) : <div className="bg-emerald-100 text-emerald-600 rounded-full text-center px-2.5 py-1">{props.status}</div>
(props.status === statusMap.completed) ? ( ) : (
<div className="bg-emerald-100 text-emerald-600 rounded-full text-center px-2.5 py-1"> <div className="bg-rose-100 text-rose-600 rounded-full text-center px-2.5 py-1">{props.status}</div>
{props.status} )}
</div>) : (
<div className="bg-rose-100 text-rose-600 rounded-full text-center px-2.5 py-1">
{props.status}
</div>)
}
</div> </div>
</td> </td>
<td className="px-2 py-3 whitespace-nowrap w-[340px] box-border"> <td className="px-2 py-3 whitespace-nowrap w-[340px] box-border">
<div className="flex flex-wrap items-center -m-1.5 justify-center"> <div className="flex flex-wrap items-center -m-1.5 justify-center">
<div className="flex -space-x-3 -ml-0.5"> <div className="flex -space-x-3 -ml-0.5">
{(props.avatars) ? ( {props.avatars
props.avatars.map((avatar, index) => ( ? props.avatars.map((avatar, index) => (
<img className="rounded-full border-2 border-slate-100 box-content" key={index} src={avatar} width="32" height="32" alt="Avatar" /> <img
className="rounded-full border-2 border-slate-100 box-content"
key={index}
src={avatar}
width="32"
height="32"
alt="Avatar"
/>
)) ))
): null} : null}
<button className="flex justify-center items-center w-9 h-9 rounded-full bg-white border-2 border-slate-200 hover:border-slate-300 text-indigo-500 shadow-sm transition duration-150"> <button className="flex justify-center items-center w-9 h-9 rounded-full bg-white border-2 border-slate-200 hover:border-slate-300 text-indigo-500 shadow-sm transition duration-150">
<span className="sr-only">Add avatar</span> <span className="sr-only">Add avatar</span>
<svg className="w-4 h-4 fill-current" viewBox="0 0 16 16"> <svg className="w-4 h-4 fill-current" viewBox="0 0 16 16">
<path d="M15 7H9V1c0-.6-.4-1-1-1S7 .4 7 1v6H1c-.6 0-1 .4-1 1s.4 1 1 1h6v6c0 .6.4 1 1 1s1-.4 1-1V9h6c.6 0 1-.4 1-1s-.4-1-1-1z" /> <path d="M15 7H9V1c0-.6-.4-1-1-1S7 .4 7 1v6H1c-.6 0-1 .4-1 1s.4 1 1 1h6v6c0 .6.4 1 1 1s1-.4 1-1V9h6c.6 0 1-.4 1-1s-.4-1-1-1z" />
</svg> </svg>
</button> </button>
</div> </div>
</div> </div>
@@ -75,31 +87,40 @@ function ProfileTableItem(props) {
</div> </div>
</td> </td>
<td className="py-3 whitespace-nowrap w-px pr-1.5"> <td className="py-3 whitespace-nowrap w-px pr-1.5">
<div className="flex items-center"> <div className="flex items-center">
<button <button
className={`text-slate-400 hover:text-slate-500 transform ${descriptionOpen && 'rotate-180'}`} className={`text-slate-400 hover:text-slate-500 transform ${descriptionOpen && 'rotate-180'}`}
aria-expanded={descriptionOpen} aria-expanded={descriptionOpen}
onClick={() => setDescriptionOpen(!descriptionOpen)} onClick={() => setDescriptionOpen(!descriptionOpen)}
aria-controls={`description-${props.id}`} aria-controls={`description-${props.id}`}
> >
<span className="sr-only">Show more</span> <span className="sr-only">Show more</span>
<svg className="w-8 h-8 fill-current" viewBox="0 0 32 32"> <svg className="w-8 h-8 fill-current" viewBox="0 0 32 32">
<path d="M16 20l-5.4-5.4 1.4-1.4 4 4 4-4 1.4 1.4z" /> <path d="M16 20l-5.4-5.4 1.4-1.4 4 4 4-4 1.4 1.4z" />
</svg> </svg>
</button> </button>
</div> </div>
</td> </td>
</tr> </tr>
<tr className={`${!descriptionOpen && 'hidden'}` }> <tr className={`${!descriptionOpen && 'hidden'}`}>
<td colSpan="10" className="px-12 pt-3.5 pb-[14px]"> <td colSpan="10" className="px-12 pt-3.5 pb-[14px]">
<div className="flex items-center gap-x-5"> <div className="flex items-center gap-x-5">
<div> <div>
<label className="block text-sm font-medium mb-1" htmlFor="placeholder">Seed</label> <label className="block text-sm font-medium mb-1" htmlFor="placeholder">
<input id="placeholder" className="form-input w-[396px] bg-white" type="text" placeholder="2342423423423234223" /> Seed
</label>
<input
id="placeholder"
className="form-input w-[396px] bg-white"
type="text"
placeholder="2342423423423234223"
/>
</div> </div>
<div> <div>
<span className="block text-sm font-medium mb-1">Transaction</span> <span className="block text-sm font-medium mb-1">Transaction</span>
<a href="" className="w-[396px] text-slate-400 font-normal text-sm underline">0x12831823791203192418234841238468</a> <a href="" className="w-[396px] text-slate-400 font-normal text-sm underline">
0x12831823791203192418234841238468
</a>
</div> </div>
</div> </div>
{/* Progress validation bar */} {/* Progress validation bar */}
@@ -114,8 +135,11 @@ function ProfileTableItem(props) {
{props.transactions.map((data, index) => ( {props.transactions.map((data, index) => (
<li className="relative py-2" key={index}> <li className="relative py-2" key={index}>
<div className="flex items-center mb-2.5"> <div className="flex items-center mb-2.5">
{(props.transactions[index+1]) ? ( {props.transactions[index + 1] ? (
<div className="absolute left-0 h-full w-0.5 bg-slate-200 self-start ml-2.5 -translate-x-1/2 translate-y-3" aria-hidden="true"></div> <div
className="absolute left-0 h-full w-0.5 bg-slate-200 self-start ml-2.5 -translate-x-1/2 translate-y-3"
aria-hidden="true"
></div>
) : null} ) : null}
<div className="absolute left-0 rounded-full bg-indigo-500" aria-hidden="true"> <div className="absolute left-0 rounded-full bg-indigo-500" aria-hidden="true">
<svg className="w-5 h-5 fill-current text-white" viewBox="0 0 20 20"> <svg className="w-5 h-5 fill-current text-white" viewBox="0 0 20 20">
@@ -124,15 +148,21 @@ function ProfileTableItem(props) {
</div> </div>
<h3 className="pl-9 whitespace-nowrap"> <h3 className="pl-9 whitespace-nowrap">
<span className="text-validateSize font-bold text-slate-800">Validate by </span> <span className="text-validateSize font-bold text-slate-800">Validate by </span>
<a href="" className="font-bold text-validateSize underline text-indigo-500">{data}</a> <a href="" className="font-bold text-validateSize underline text-indigo-500">
{data}
</a>
</h3> </h3>
</div> </div>
<div className="pl-9"> <div className="pl-9">
<a href="" className="w-[396px] text-slate-800 font-semibold text-base underline">{data}</a> <a href="" className="w-[396px] text-slate-800 font-semibold text-base underline">
{data}
</a>
<span className="block text-xxs font-normal mb-1">Transactions ID</span> <span className="block text-xxs font-normal mb-1">Transactions ID</span>
</div> </div>
<div className="pl-9"> <div className="pl-9">
<a href="" className="w-[396px] text-slate-800 font-semibold text-base underline">{data.slice(2, data.length)}</a> <a href="" className="w-[396px] text-slate-800 font-semibold text-base underline">
{data.slice(2, data.length)}
</a>
<span className="block text-xxs font-normal mb-1">Validated data</span> <span className="block text-xxs font-normal mb-1">Validated data</span>
</div> </div>
<div className="pl-9 pt-[14px]"> <div className="pl-9 pt-[14px]">
@@ -147,8 +177,8 @@ function ProfileTableItem(props) {
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
</> </>
); );
} }

View File

@@ -8,8 +8,9 @@ function prepareUrl(url) {
function handleRequest(method, url, headers, attempts, token, body) { function handleRequest(method, url, headers, attempts, token, body) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
store.loading = true;
(function internalRequest() { (function internalRequest() {
if(store)
store.loading = true;
return request(method, url, headers, token, body) return request(method, url, headers, token, body)
.then(resolve) .then(resolve)
.catch(err => --attempts > 0 ? internalRequest() : reject(err)) .catch(err => --attempts > 0 ? internalRequest() : reject(err))

View File

@@ -2,5 +2,6 @@ export const statusMap={
completed:'Completed', completed:'Completed',
incorrect:'Incorrect', incorrect:'Incorrect',
stored: 'Stored', stored: 'Stored',
blockchained: 'Blockchained' blockchained: 'Blockchained',
processed: 'Processed'
} }

View File

@@ -1,169 +1,202 @@
import {reaction, makeAutoObservable, onBecomeObserved, onBecomeUnobserved} from "mobx"; import { reaction, makeAutoObservable, onBecomeObserved, onBecomeUnobserved } from 'mobx';
import {cryptography} from "@liskhq/lisk-client"; import { cryptography } from '@liskhq/lisk-client';
import { passphrase, transactions } from "@liskhq/lisk-client"; import { passphrase } from '@liskhq/lisk-client';
import {getNodeInfo} from '../api/node'; import { getNodeInfo } from '../api/node';
import {fetchWrapper} from '../shared/fetchWrapper'; import { fetchWrapper } from '../shared/fetchWrapper';
import {labelMap} from "../shared/labelMap"; import { labelMap } from '../shared/labelMap';
import {generateSvgAvatar} from "../images/GenerateOnboardingSvg/GenerateSvg"; import { generateSvgAvatar } from '../images/GenerateOnboardingSvg/GenerateSvg';
import {decryptedData} from "../utils/decryptedData"; import {decryptedData} from "../utils/decryptedData";
import { import { encryptAccountData, generateTransaction, hashAccountData } from '../utils/Utils';
encryptAccountData,
generateSetTransaction, generateTransaction,
hashAccountData,
} from '../utils/Utils';
import {
removeFeatureAssetSchema,
setFeatureAssetSchema,
} from '../utils/Schemas';
class Store { class Store {
_accountData = [] _accountData = [];
_passPhrase = '' _passPhrase = '';
_nodeInfo = {} _nodeInfo = {};
_keysArray = [] _keysArray = [];
_sharedData = [] _sharedData = [];
_transactionsInfo = [] _transactionsInfo = [];
_accountInfo = {}; _accountInfo = {};
_loading = false; _loading = false;
_tempTransactions = [];
constructor() { constructor() {
makeAutoObservable(this, {}); makeAutoObservable(this, {});
reaction(() => this.keysArray, () => this.fetchSharedData()) reaction(
reaction(() => this.address, () => this.fetchAccountInfo()) () => this.keysArray,
onBecomeObserved(this, "decryptedAccountData", () => this.fetchNewAccountData()) () => this.fetchSharedData()
onBecomeObserved(this, "sharedData", () => this.fetchKeysArray()) );
onBecomeUnobserved(this, "sharedData", () => this.unobservedSharedData()) reaction(
onBecomeObserved(this, "transactionsInfo", () => this.fetchTransactionsInfo()) () => this.address,
onBecomeUnobserved(this, "transactionsInfo", () => this.unobservedTransactionsInfo()) () => this.fetchAccountInfo()
);
onBecomeObserved(this, 'decryptedAccountData', () => this.fetchNewAccountData());
onBecomeObserved(this, 'sharedData', () => this.fetchKeysArray());
onBecomeUnobserved(this, 'sharedData', () => this.unobservedSharedData());
onBecomeObserved(this, 'transactionsInfo', () => this.fetchTransactionsInfo());
onBecomeUnobserved(this, 'transactionsInfo', () => this.unobservedTransactionsInfo());
this.fetchNodeInfo() this.fetchNodeInfo();
}; }
fetchNewAccountData() { fetchNewAccountData() {
getNodeInfo() getNodeInfo()
.then((info)=>{ .then((info) => {
this.fetchNodeInfoSuccess(info) this.fetchNodeInfoSuccess(info);
fetchWrapper.getAuth('data/private', { fetchWrapper
networkIdentifier: this.nodeInfo.networkIdentifier, .getAuth('data/private', {
lastBlockID: this.nodeInfo.lastBlockID networkIdentifier: this.nodeInfo.networkIdentifier,
}).then((res) => this.accountDataFetchChange(res)) lastBlockID: this.nodeInfo.lastBlockID,
}) })
.catch((err) => this.fetchNodeInfoFailed(err)) .then((res) => this.accountDataFetchChange(res))
.catch((err) => this.fetchError(err));
})
.catch((err) => this.fetchError(err));
} }
fetchAccountInfo() { fetchAccountInfo() {
fetchWrapper.get(`accounts/${this.address}`).then((res) => this.fetchAccountInfoSuccess(res)) fetchWrapper
.get(`accounts/${this.address}`)
.then((res) => this.fetchAccountInfoSuccess(res))
.catch((err) => this.fetchError(err));
} }
fetchKeysArray() { fetchKeysArray() {
getNodeInfo() getNodeInfo()
.then((info)=>{ .then((info) => {
this.fetchNodeInfoSuccess(info) this.fetchNodeInfoSuccess(info);
fetchWrapper.getAuth('data/shared/', { fetchWrapper
.getAuth('data/shared/', {
networkIdentifier: this.nodeInfo.networkIdentifier, networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID lastBlockID: this.nodeInfo.lastBlockID,
}).then((res) => this.keysArrayFetchChange(res)) })
.then((res) => this.keysArrayFetchChange(res));
}) })
.catch((err) => this.fetchNodeInfoFailed(err)) .catch((err) => this.fetchError(err));
} }
fetchTransactionsInfo() { fetchTransactionsInfo() {
fetchWrapper.get(`account/transactions/${this.address}`, { fetchWrapper
.get(`account/transactions/${this.address}`, {
networkIdentifier: this.nodeInfo.networkIdentifier, networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID lastBlockID: this.nodeInfo.lastBlockID,
}).then((res) => this.saveInfoTransactions(res)) })
}; .then((res) => this.saveInfoTransactions(res))
.catch((err) => this.fetchError(err));
}
fetchTempTransactions() {
fetchWrapper
.get('node/transactions')
.then((res) => this.fetchTempTransactionsSuccess(res))
.catch((err) => this.fetchError(err));
}
fetchPassPhrase() { fetchPassPhrase() {
this._passPhrase = sessionStorage.getItem('passPhrase') || '' this._passPhrase = sessionStorage.getItem('passPhrase') || '';
} }
fetchSharedData() { fetchSharedData() {
this._keysArray.forEach((elem) => fetchWrapper.get(`data/shared/${elem}`).then((res) => this.changeSharedData(res))) this._keysArray.forEach((elem) =>
}; fetchWrapper
.get(`data/shared/${elem}`)
.then((res) => this.changeSharedData(res))
.catch((err) => this.fetchError(err))
);
}
fetchNodeInfo() { fetchNodeInfo() {
getNodeInfo() getNodeInfo()
.then((info)=>this.fetchNodeInfoSuccess(info)) .then((info) => this.fetchNodeInfoSuccess(info))
.catch((err) => this.fetchNodeInfoFailed(err)) .catch((err) => this.fetchError(err));
} }
pushAccountData(data = this.accountData) { pushAccountData(data = this.accountData) {
fetchWrapper.postAuth('data/private', { fetchWrapper
networkIdentifier: this.nodeInfo.networkIdentifier, .postAuth(
lastBlockID: this.nodeInfo.lastBlockID 'data/private',
}, [...encryptAccountData(data, this.passPhrase, this.pubKey)]) {
.then(() => this.fetchNewAccountData()) networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID,
},
[...encryptAccountData(data, this.passPhrase, this.pubKey)]
)
.then(() => this.fetchNewAccountData())
.catch((err) => this.fetchError(err));
} }
pushAccountDataToBlockchain(data = this.decryptedAccountData) { pushAccountDataToBlockchain(data = this.decryptedAccountData) {
const [removed, changed] = hashAccountData(data, this.decryptedAccountData, this.accountFeaturesMap) const [removed, changed] = hashAccountData(data, this.decryptedAccountData, this.accountFeaturesMap);
const builder = generateTransaction(BigInt(this.accountInfo?.sequence?.nonce || 0), this.addressAndPubKey.publicKey, this.nodeInfo.networkIdentifier, this.passPhrase); const builder = generateTransaction(
BigInt(this.accountInfo?.sequence?.nonce || 0),
this.addressAndPubKey.publicKey,
this.nodeInfo.networkIdentifier,
this.passPhrase
);
let signedTx = null; let signedTx = null;
if(removed.length !== 0) if (removed.length !== 0) signedTx = builder.remove(removed);
signedTx = builder.remove(removed);
if(changed.length !== 0) if (changed.length !== 0) signedTx = builder.update(changed);
signedTx = builder.update(changed) if (signedTx) {
if(signedTx) { fetchWrapper.post('transactions', {}, signedTx)
fetchWrapper.post('transactions', {}, signedTx); .then(() => this.fetchTempTransactions())
.catch((err) => this.fetchError(err));
this.accountInfo.sequence.nonce++; this.accountInfo.sequence.nonce++;
} }
} }
generatePassPhrase() { generatePassPhrase() {
this._passPhrase = passphrase.Mnemonic.generateMnemonic(); this._passPhrase = passphrase.Mnemonic.generateMnemonic();
sessionStorage.setItem('passPhrase', this._passPhrase); sessionStorage.setItem('passPhrase', this._passPhrase);
}; }
savePastPassPhrase(phrase) { savePastPassPhrase(phrase) {
this._passPhrase=phrase this._passPhrase = phrase;
sessionStorage.setItem('passPhrase', this._passPhrase); sessionStorage.setItem('passPhrase', this._passPhrase);
}; }
unobservedTransactionsInfo() { unobservedTransactionsInfo() {
this._transactionsInfo = [] this._transactionsInfo = [];
}; }
unobservedSharedData() { unobservedSharedData() {
this._sharedData = [] this._sharedData = [];
}; }
changeSharedData(incomingData) { changeSharedData(incomingData) {
this._sharedData.push({ this._sharedData.push({
data: incomingData.data, data: incomingData.data,
}) });
} }
saveDataRegistration(data) { saveDataRegistration(data) {
this._accountData = data; this._accountData = data;
}; }
clearDataRegistration() { clearDataRegistration() {
this._accountData = []; this._accountData = [];
}; }
saveInfoTransactions(transaction) { saveInfoTransactions(transaction) {
this._transactionsInfo = transaction.data this._transactionsInfo = transaction.data;
} }
accountDataFetchChange(res) { accountDataFetchChange(res) {
if (res.data) { if (res.data) {
this._accountData = res.data; this._accountData = res.data;
} }
}; this.fetchTempTransactions();
}
keysArrayFetchChange(res) { keysArrayFetchChange(res) {
this._keysArray = res.data; this._keysArray = res.data;
@@ -171,59 +204,67 @@ class Store {
fetchNodeInfoSuccess(info) { fetchNodeInfoSuccess(info) {
this._nodeInfo = info.data; this._nodeInfo = info.data;
this.fetchPassPhrase() this.fetchPassPhrase();
}
fetchNodeInfoFailed(err) {
console.log(err);
} }
fetchAccountInfoSuccess(res) { fetchAccountInfoSuccess(res) {
this._accountInfo = res.data; this._accountInfo = res.data;
if(this.accountInfo?.sequence?.nonce) if (this.accountInfo?.sequence?.nonce)
this.accountInfo.sequence.nonce = parseInt(this.accountInfo.sequence.nonce) || 0 this.accountInfo.sequence.nonce = parseInt(this.accountInfo.sequence.nonce) || 0;
}
fetchTempTransactionsSuccess(res) {
this._tempTransactions = res.data;
}
fetchError(err) {
console.log(err);
} }
get sharedData() { get sharedData() {
return this._sharedData.map(elem => ({ return this._sharedData.map((elem) => ({
data: elem.data.map(item => ({ data: elem.data.map((item) => ({
label: labelMap[item.label], label: labelMap[item.label],
value: item.value, value: item.value,
})) })),
})); }));
}; }
get transactionsInfo() { get transactionsInfo() {
return this._transactionsInfo.map(item => { return this._transactionsInfo.map((item) => {
return { return {
id: item.id, id: item.id,
sender_avatar: item.asset.recipientAddress && generateSvgAvatar(item.senderPublicKey), sender_avatar: item.asset.recipientAddress && generateSvgAvatar(item.senderPublicKey),
avatar_size: 24, avatar_size: 24,
transaction: item.asset.features.map(asset => { transaction: item.asset.features.map((asset) => {
return { return {
transaction_id: item.id, transaction_id: item.id,
address: item.asset.recipientAddress && cryptography.bufferToHex(cryptography.getAddressFromPublicKey(cryptography.hexToBuffer(item.senderPublicKey))), address:
item.asset.recipientAddress &&
cryptography.bufferToHex(
cryptography.getAddressFromPublicKey(cryptography.hexToBuffer(item.senderPublicKey))
),
value: asset.value, value: asset.value,
label: labelMap[asset.label] || asset.label label: labelMap[asset.label] || asset.label,
} };
}) }),
} };
}) });
} }
get decryptedAccountData() { get decryptedAccountData() {
return decryptedData(this._accountData, this.accountFeatures, this.passPhrase, this.pubKey) return decryptedData(this._accountData, this.accountFeatures, this.passPhrase, this.pubKey)
} }
get firstName() { get firstName() {
return this.decryptedAccountData.find(item => item.key === 'firstname')?.value return this.decryptedAccountData.find((item) => item.key === 'firstname')?.value;
} }
get lastName() { get lastName() {
return this.decryptedAccountData.find(item => item.key === 'secondname')?.value return this.decryptedAccountData.find((item) => item.key === 'secondname')?.value;
} }
get accountName() { get accountName() {
return this.firstName || this.lastName || this.pubKey return this.firstName || this.lastName || this.pubKey;
} }
get keysArray() { get keysArray() {
@@ -231,12 +272,12 @@ class Store {
} }
get passPhrase() { get passPhrase() {
return this._passPhrase return this._passPhrase;
} }
get accountData() { get accountData() {
return this._accountData return this._accountData;
}; }
get accountInfo() { get accountInfo() {
return this._accountInfo; return this._accountInfo;
@@ -255,15 +296,14 @@ class Store {
} }
get address() { get address() {
return this.addressAndPubKey.address.toString('hex') return this.addressAndPubKey.address.toString('hex');
} }
get tokenKey() { get tokenKey() {
const stringToSign = this.nodeInfo.networkIdentifier + this.nodeInfo.lastBlockID; const stringToSign = this.nodeInfo.networkIdentifier + this.nodeInfo.lastBlockID;
if(!stringToSign) if (!stringToSign) return '';
return ''; const sign = cryptography.signDataWithPassphrase(Buffer.from(stringToSign, 'hex'), this.passPhrase).toString('hex');
const sign = cryptography.signDataWithPassphrase(Buffer.from(stringToSign, 'hex'), this.passPhrase).toString('hex') return this.pubKey + ':' + sign;
return this.pubKey + ':' +sign
} }
get accountIdentity() { get accountIdentity() {
@@ -275,10 +315,13 @@ class Store {
} }
get accountFeaturesMap() { get accountFeaturesMap() {
return this.accountFeatures.reduce((acc, item) => ({ return this.accountFeatures.reduce(
...acc, (acc, item) => ({
[item.label]: item.value ...acc,
}), {}) [item.label]: item.value,
}),
{}
);
} }
get loading() { get loading() {
@@ -288,6 +331,22 @@ class Store {
set loading(value) { set loading(value) {
this._loading = value; this._loading = value;
} }
get tempTransactions() {
return this._tempTransactions;
}
get processedFeatures() {
return this.tempTransactions
.filter(item => item.senderPublicKey === this.pubKey)
.reduce((acc, item) => {
const { features } = item.asset;
return {
...acc,
...features.reduce((obj, feature) => ({...obj, [feature.label]: true}), {})
}
}, {})
}
} }
export const store = new Store(); export const store = new Store();