Merge pull request #57 from franze6/DID-13

Fixed delete and update data account
This commit is contained in:
Kirill Andrusyak
2022-08-24 10:08:39 +03:00
committed by GitHub
4 changed files with 22 additions and 16 deletions

View File

@@ -127,10 +127,10 @@ const Profile = observer (() => {
};
const deleteDataParameters = () => {
const changeData = store.decryptedAccountData.filter(item=>!selectedItems.includes(item.key))
const changeData = store.decryptedAccountData.filter(item=>!selectedItems.includes(item.key));
store.pushAccountData(changeData);
if(storeOnBlockchain)
store.pushAccountDataToBlockchain(changeData)
store.pushAccountDataToBlockchain(changeData.filter(elem=>elem.status!=='Stored'))
};
const changeInitialArray = () => {
@@ -140,6 +140,7 @@ const Profile = observer (() => {
if (elem.label === item.label) {
newArr.push({
...elem,
status: 'new',
'value': item.value,
'seed': item.seed,
})
@@ -156,10 +157,11 @@ const Profile = observer (() => {
const updatedData = changeInitialArray();
store.pushAccountData(updatedData);
if(storeOnBlockchain)
store.pushAccountDataToBlockchain(updatedData)
store.pushAccountDataToBlockchain(updatedData.filter(elem=>elem.status!=='Stored'))
};
const addDataParameters = () => {
console.log(addedValues)
const label = addedValues.label.toLowerCase().split(' ').join('');
if(labelMap[label])
addedValues.key = addedValues.label.toLowerCase().split(' ').join('');
@@ -167,7 +169,7 @@ const Profile = observer (() => {
addedValues.key = addedValues.label
store.pushAccountData(store.decryptedAccountData.concat(addedValues));
if(storeOnBlockchain)
store.pushAccountDataToBlockchain(store.decryptedAccountData.concat(addedValues))
store.pushAccountDataToBlockchain(store.decryptedAccountData.concat(addedValues).filter(elem=>elem.status!=='Stored'))
};
const cancelAddPanel = () => {

6
src/shared/statusMap.js Normal file
View File

@@ -0,0 +1,6 @@
export const statusMap={
completed:'Completed',
incorrect:'Incorrect',
stored: 'Stored',
blockchained: 'Blockchained'
}

View File

@@ -4,6 +4,7 @@ import { passphrase, transactions } 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 {
encryptAccountData,
@@ -105,7 +106,6 @@ class Store {
pushAccountDataToBlockchain(data = this.decryptedAccountData) {
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);
let signedTx = null;
@@ -115,7 +115,6 @@ class Store {
if(changed.length !== 0)
signedTx = builder.update(changed)
if(signedTx) {
fetchWrapper.post('transactions', {}, signedTx);
this.accountInfo.sequence.nonce++;
@@ -226,7 +225,7 @@ class Store {
if(!this._accountData.find(item=>item.label===elem.label)) {
return {
...initialData,
status: 'Blockchained',
status: statusMap.blockchained,
value: elem.value
}
}
@@ -235,7 +234,7 @@ class Store {
if(!this.accountFeatures.find(item=>item.label===elem.label)) {
return {
...initialData,
status: 'Stored',
status: statusMap.stored,
value,
seed
}
@@ -243,14 +242,14 @@ class Store {
if(this.accountFeatures.find(item=>item.label===elem.label).value!==hashValue) {
return {
...initialData,
status: 'Incorrect',
status: statusMap.incorrect,
value,
seed
}
}
return {
...initialData,
status: 'Completed',
status: statusMap.completed,
value,
seed
}

View File

@@ -1,6 +1,8 @@
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
@@ -36,7 +38,7 @@ export const formatThousands = (value) => Intl.NumberFormat('en-US', {
}).format(value);
export const encryptAccountData = (data = [], passPhrase = '', pubKey = '') => {
return data.map((item) => {
return data.filter(item=>item.status!==statusMap.blockchained).map((item) => {
let value = cryptography.encryptMessageWithPassphrase(item.seed + ":" + item.value, passPhrase, pubKey);
return {
label: item.key,
@@ -57,9 +59,8 @@ export const hashAccountData = (data = [], oldData = [], hashMap = {}) => {
...acc,
[item.label]: item.value
}), {})
const removed = oldData.reduce((acc, item) => {
if(!accountMap[item.label] && hashMap[item.label])
if(!accountMap[item.label] && !data.find(elem=>elem.label===item.label))
return [...acc, {label: item.label}];
return acc
}, [])
@@ -69,11 +70,10 @@ export const hashAccountData = (data = [], oldData = [], hashMap = {}) => {
return [ ...acc, item ]
const oldValue = hashMap[item.key];
const newValue = hashValue(item.value, item.seed).toString('hex')
if(oldValue !== newValue)
if(oldValue !== newValue && item.status==='new')
return [ ...acc, item ]
return acc;
}, [])
return [
removed,
changed.map((item) => {
@@ -144,7 +144,6 @@ export const generateRemoveTransaction = (features, nonce = BigInt(0), senderPub
features
},
}
const signedTx = transactions.signTransaction(removeFeatureAssetSchema,
tx, Buffer.from(networkIdentifier, "hex"),
passPhrase)