Added the ability to share account data
This commit is contained in:
@@ -165,6 +165,11 @@ const Profile = observer (() => {
|
||||
store.pushAccountDataToBlockchain(updatedData.filter(elem=>elem.status!=='Stored'))
|
||||
};
|
||||
|
||||
const sharedDataAccount = () => {
|
||||
const sharedData = store.decryptedAccountData.filter(item => selectedItems.includes(item.key))
|
||||
store.pushSharedData(sharedData)
|
||||
}
|
||||
|
||||
const addDataParameters = () => {
|
||||
const label = addedValues.label.toLowerCase().split(' ').join('');
|
||||
if(labelMap[label])
|
||||
@@ -517,7 +522,10 @@ const Profile = observer (() => {
|
||||
</svg>
|
||||
<span className="ml-2">Update</span>
|
||||
</button>
|
||||
<button className="btn w-full border-slate-200 hover:border-slate-300 text-slate-600 px-[100px] justify-start">
|
||||
<button
|
||||
className="btn w-full border-slate-200 hover:border-slate-300 text-slate-600 px-[100px] justify-start"
|
||||
onClick={sharedDataAccount}
|
||||
>
|
||||
<svg className="w-4 h-4 fill-rose-500 shrink-0" viewBox="0 0 16 16">
|
||||
<path d="M14.682 2.318A4.485 4.485 0 0 0 11.5 1 4.377 4.377 0 0 0 8 2.707 4.383 4.383 0 0 0 4.5 1a4.5 4.5 0 0 0-3.182 7.682L8 15l6.682-6.318a4.5 4.5 0 0 0 0-6.364Zm-1.4 4.933L8 12.247l-5.285-5A2.5 2.5 0 0 1 4.5 3c1.437 0 2.312.681 3.5 2.625C9.187 3.681 10.062 3 11.5 3a2.5 2.5 0 0 1 1.785 4.251h-.003Z" />
|
||||
</svg>
|
||||
|
||||
@@ -4,9 +4,10 @@ import { passphrase } from '@liskhq/lisk-client';
|
||||
import { getNodeInfo } from '../api/node';
|
||||
import { fetchWrapper } from '../shared/fetchWrapper';
|
||||
import { labelMap } from '../shared/labelMap';
|
||||
import { statusMap } from "../shared/statusMap";
|
||||
import { generateSvgAvatar } from '../images/GenerateOnboardingSvg/GenerateSvg';
|
||||
import {decryptedData} from "../utils/decryptedData";
|
||||
import { encryptAccountData, generateTransaction, hashAccountData } from '../utils/Utils';
|
||||
import {encryptAccountData, encryptSharedData, generateTransaction, hashAccountData} from '../utils/Utils';
|
||||
|
||||
class Store {
|
||||
_accountData = [];
|
||||
@@ -39,6 +40,7 @@ class Store {
|
||||
() => this.fetchAccountInfo()
|
||||
);
|
||||
onBecomeObserved(this, 'decryptedAccountData', () => this.fetchNewAccountData());
|
||||
onBecomeUnobserved(this, 'decryptedAccountData', () => this.unobservedAccountData())
|
||||
onBecomeObserved(this, 'sharedData', () => this.fetchKeysArray());
|
||||
onBecomeUnobserved(this, 'sharedData', () => this.unobservedSharedData());
|
||||
onBecomeObserved(this, 'transactionsInfo', () => this.fetchTransactionsInfo());
|
||||
@@ -105,11 +107,12 @@ class Store {
|
||||
}
|
||||
|
||||
fetchSharedData() {
|
||||
this._keysArray.forEach((elem) =>
|
||||
this._keysArray.forEach((elem) => {
|
||||
fetchWrapper
|
||||
.get(`data/shared/${elem}`)
|
||||
.then((res) => this.changeSharedData(res))
|
||||
.catch((err) => this.fetchError(err))
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,6 +122,22 @@ class Store {
|
||||
.catch((err) => this.fetchError(err));
|
||||
}
|
||||
|
||||
pushSharedData(data) {
|
||||
data=data.filter(item=>item.status!==statusMap.blockchained)
|
||||
if(data.length>0) {
|
||||
fetchWrapper
|
||||
.postAuth(
|
||||
'data/shared',
|
||||
{
|
||||
networkIdentifier: this.nodeInfo.networkIdentifier,
|
||||
lastBlockID: this.nodeInfo.lastBlockID,
|
||||
},
|
||||
{publickey: this.pubKey, shared: encryptSharedData(data, this.passPhrase, this.pubKey)}
|
||||
)
|
||||
.catch((err) => this.fetchError(err));
|
||||
}
|
||||
}
|
||||
|
||||
pushAccountData(data = this.accountData) {
|
||||
fetchWrapper
|
||||
.postAuth(
|
||||
@@ -173,6 +192,10 @@ class Store {
|
||||
this._sharedData = [];
|
||||
}
|
||||
|
||||
unobservedAccountData() {
|
||||
this._accountData=[]
|
||||
}
|
||||
|
||||
changeSharedData(incomingData) {
|
||||
this._sharedData.push({
|
||||
data: incomingData.data,
|
||||
@@ -224,7 +247,7 @@ class Store {
|
||||
get sharedData() {
|
||||
return this._sharedData.map((elem) => ({
|
||||
data: elem.data.map((item) => ({
|
||||
label: labelMap[item.label],
|
||||
label: labelMap[item.label] || item.label,
|
||||
value: item.value,
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -2,7 +2,6 @@ import resolveConfig from 'tailwindcss/resolveConfig';
|
||||
import {cryptography, transactions} from '@liskhq/lisk-client';
|
||||
import {removeFeatureAssetSchema, setFeatureAssetSchema} from './Schemas';
|
||||
import {statusMap} from "../shared/statusMap";
|
||||
import {labelMap} from "../shared/labelMap";
|
||||
|
||||
export const tailwindConfig = () => {
|
||||
// Tailwind config
|
||||
@@ -49,6 +48,17 @@ export const encryptAccountData = (data = [], passPhrase = '', pubKey = '') => {
|
||||
})
|
||||
}
|
||||
|
||||
export const encryptSharedData = (data = [], passPhrase = '', pubKey = '') => {
|
||||
return data.map((item)=> {
|
||||
let value = cryptography.encryptMessageWithPassphrase(item.seed + ":" + item.value, passPhrase, pubKey);
|
||||
return {
|
||||
label: item.key,
|
||||
value: value.encryptedMessage,
|
||||
value_nonce: value.nonce,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const hashAccountData = (data = [], oldData = [], hashMap = {}) => {
|
||||
const accountMap = data.reduce((acc, item) => ({
|
||||
...acc,
|
||||
|
||||
Reference in New Issue
Block a user