Merge pull request #57 from franze6/DID-13
Fixed delete and update data account
This commit is contained in:
@@ -127,10 +127,10 @@ const Profile = observer (() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deleteDataParameters = () => {
|
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);
|
store.pushAccountData(changeData);
|
||||||
if(storeOnBlockchain)
|
if(storeOnBlockchain)
|
||||||
store.pushAccountDataToBlockchain(changeData)
|
store.pushAccountDataToBlockchain(changeData.filter(elem=>elem.status!=='Stored'))
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeInitialArray = () => {
|
const changeInitialArray = () => {
|
||||||
@@ -140,6 +140,7 @@ const Profile = observer (() => {
|
|||||||
if (elem.label === item.label) {
|
if (elem.label === item.label) {
|
||||||
newArr.push({
|
newArr.push({
|
||||||
...elem,
|
...elem,
|
||||||
|
status: 'new',
|
||||||
'value': item.value,
|
'value': item.value,
|
||||||
'seed': item.seed,
|
'seed': item.seed,
|
||||||
})
|
})
|
||||||
@@ -156,10 +157,11 @@ const Profile = observer (() => {
|
|||||||
const updatedData = changeInitialArray();
|
const updatedData = changeInitialArray();
|
||||||
store.pushAccountData(updatedData);
|
store.pushAccountData(updatedData);
|
||||||
if(storeOnBlockchain)
|
if(storeOnBlockchain)
|
||||||
store.pushAccountDataToBlockchain(updatedData)
|
store.pushAccountDataToBlockchain(updatedData.filter(elem=>elem.status!=='Stored'))
|
||||||
};
|
};
|
||||||
|
|
||||||
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('');
|
||||||
@@ -167,7 +169,7 @@ const Profile = observer (() => {
|
|||||||
addedValues.key = addedValues.label
|
addedValues.key = addedValues.label
|
||||||
store.pushAccountData(store.decryptedAccountData.concat(addedValues));
|
store.pushAccountData(store.decryptedAccountData.concat(addedValues));
|
||||||
if(storeOnBlockchain)
|
if(storeOnBlockchain)
|
||||||
store.pushAccountDataToBlockchain(store.decryptedAccountData.concat(addedValues))
|
store.pushAccountDataToBlockchain(store.decryptedAccountData.concat(addedValues).filter(elem=>elem.status!=='Stored'))
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelAddPanel = () => {
|
const cancelAddPanel = () => {
|
||||||
|
|||||||
6
src/shared/statusMap.js
Normal file
6
src/shared/statusMap.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export const statusMap={
|
||||||
|
completed:'Completed',
|
||||||
|
incorrect:'Incorrect',
|
||||||
|
stored: 'Stored',
|
||||||
|
blockchained: 'Blockchained'
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import { passphrase, transactions } 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 {statusMap} from "../shared/statusMap";
|
||||||
import {generateSvgAvatar} from "../images/GenerateOnboardingSvg/GenerateSvg";
|
import {generateSvgAvatar} from "../images/GenerateOnboardingSvg/GenerateSvg";
|
||||||
import {
|
import {
|
||||||
encryptAccountData,
|
encryptAccountData,
|
||||||
@@ -105,7 +106,6 @@ class Store {
|
|||||||
|
|
||||||
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;
|
||||||
@@ -115,7 +115,6 @@ class Store {
|
|||||||
|
|
||||||
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);
|
||||||
this.accountInfo.sequence.nonce++;
|
this.accountInfo.sequence.nonce++;
|
||||||
@@ -226,7 +225,7 @@ class Store {
|
|||||||
if(!this._accountData.find(item=>item.label===elem.label)) {
|
if(!this._accountData.find(item=>item.label===elem.label)) {
|
||||||
return {
|
return {
|
||||||
...initialData,
|
...initialData,
|
||||||
status: 'Blockchained',
|
status: statusMap.blockchained,
|
||||||
value: elem.value
|
value: elem.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,7 +234,7 @@ class Store {
|
|||||||
if(!this.accountFeatures.find(item=>item.label===elem.label)) {
|
if(!this.accountFeatures.find(item=>item.label===elem.label)) {
|
||||||
return {
|
return {
|
||||||
...initialData,
|
...initialData,
|
||||||
status: 'Stored',
|
status: statusMap.stored,
|
||||||
value,
|
value,
|
||||||
seed
|
seed
|
||||||
}
|
}
|
||||||
@@ -243,14 +242,14 @@ class Store {
|
|||||||
if(this.accountFeatures.find(item=>item.label===elem.label).value!==hashValue) {
|
if(this.accountFeatures.find(item=>item.label===elem.label).value!==hashValue) {
|
||||||
return {
|
return {
|
||||||
...initialData,
|
...initialData,
|
||||||
status: 'Incorrect',
|
status: statusMap.incorrect,
|
||||||
value,
|
value,
|
||||||
seed
|
seed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...initialData,
|
...initialData,
|
||||||
status: 'Completed',
|
status: statusMap.completed,
|
||||||
value,
|
value,
|
||||||
seed
|
seed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import resolveConfig from 'tailwindcss/resolveConfig';
|
import resolveConfig from 'tailwindcss/resolveConfig';
|
||||||
import {cryptography, transactions} from '@liskhq/lisk-client';
|
import {cryptography, transactions} from '@liskhq/lisk-client';
|
||||||
import {removeFeatureAssetSchema, setFeatureAssetSchema} from './Schemas';
|
import {removeFeatureAssetSchema, setFeatureAssetSchema} from './Schemas';
|
||||||
|
import {statusMap} from "../shared/statusMap";
|
||||||
|
import {labelMap} from "../shared/labelMap";
|
||||||
|
|
||||||
export const tailwindConfig = () => {
|
export const tailwindConfig = () => {
|
||||||
// Tailwind config
|
// Tailwind config
|
||||||
@@ -36,7 +38,7 @@ export const formatThousands = (value) => Intl.NumberFormat('en-US', {
|
|||||||
}).format(value);
|
}).format(value);
|
||||||
|
|
||||||
export const encryptAccountData = (data = [], passPhrase = '', pubKey = '') => {
|
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);
|
let value = cryptography.encryptMessageWithPassphrase(item.seed + ":" + item.value, passPhrase, pubKey);
|
||||||
return {
|
return {
|
||||||
label: item.key,
|
label: item.key,
|
||||||
@@ -57,9 +59,8 @@ export const hashAccountData = (data = [], oldData = [], hashMap = {}) => {
|
|||||||
...acc,
|
...acc,
|
||||||
[item.label]: item.value
|
[item.label]: item.value
|
||||||
}), {})
|
}), {})
|
||||||
|
|
||||||
const removed = oldData.reduce((acc, item) => {
|
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, {label: item.label}];
|
||||||
return acc
|
return acc
|
||||||
}, [])
|
}, [])
|
||||||
@@ -69,11 +70,10 @@ export const hashAccountData = (data = [], oldData = [], hashMap = {}) => {
|
|||||||
return [ ...acc, item ]
|
return [ ...acc, item ]
|
||||||
const oldValue = hashMap[item.key];
|
const oldValue = hashMap[item.key];
|
||||||
const newValue = hashValue(item.value, item.seed).toString('hex')
|
const newValue = hashValue(item.value, item.seed).toString('hex')
|
||||||
if(oldValue !== newValue)
|
if(oldValue !== newValue && item.status==='new')
|
||||||
return [ ...acc, item ]
|
return [ ...acc, item ]
|
||||||
return acc;
|
return acc;
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return [
|
return [
|
||||||
removed,
|
removed,
|
||||||
changed.map((item) => {
|
changed.map((item) => {
|
||||||
@@ -144,7 +144,6 @@ export const generateRemoveTransaction = (features, nonce = BigInt(0), senderPub
|
|||||||
features
|
features
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const signedTx = transactions.signTransaction(removeFeatureAssetSchema,
|
const signedTx = transactions.signTransaction(removeFeatureAssetSchema,
|
||||||
tx, Buffer.from(networkIdentifier, "hex"),
|
tx, Buffer.from(networkIdentifier, "hex"),
|
||||||
passPhrase)
|
passPhrase)
|
||||||
|
|||||||
Reference in New Issue
Block a user