diff --git a/src/pages/digitalId/Verify.jsx b/src/pages/digitalId/Verify.jsx index 570cc64..1f5bb4b 100644 --- a/src/pages/digitalId/Verify.jsx +++ b/src/pages/digitalId/Verify.jsx @@ -1,83 +1,13 @@ import React, { useState } from 'react'; import Sidebar from '../../partials/Sidebar'; import Header from '../../partials/Header'; +import { sharedDataStore } from '../../store/sharedDataStore'; +import { observer } from 'mobx-react-lite'; -const Verify = (() => { +const Verify = observer(() => { const [sidebarOpen, setSidebarOpen] = useState(false); const [descriptionOpen, setDescriptionOpen] = useState(false); - const verifiedData = [ - { - "date": "31.05.2022 10:48", - "fields": [ - { - "name": "Residence", - "value": "United Kindom", - "hash1": "7234ABC3423423523457234ABC34234", - "hash2": "7234ABC3423423523457234ABC34234" - }, - { - "name": "Document ID", - "value": "A1321313", - "hash1": "7234ABC3423423523457234ABC34234", - "hash2": "7234ABC3423423523457234ABC34234" - }, - { - "name": 'Document ID', - "value": 'A3451313', - "hash1": '9584ABC3423423523457234ABC34234', - "hash2": '9584ABC3423423523457234ABC34234' - } - ] - }, - { - "date": "31.05.2022 10:48", - "fields": [ - { - "name": 'Residence', - "value": 'Holland', - "hash1": '1024ABC3423423523457234ABC34234', - "hash2": '1024ABC3423423523457234ABC34234' - }, - { - "name": 'Document ID', - "value": 'B3451313', - "hash1": '7893ABC3423423523457234ABC34234', - "hash2": '7893ABC3423423523457234ABC34234' - }, - { - "name": 'Document ID', - "value": 'A3451313', - "hash1": '7286ABC3423423523457234ABC34234', - "hash2": '7286ABC3423423523457234ABC34234' - }, - ] - }, - { - "date": "31.05.2022 10:48", - "fields": [ - { - "name": 'Residence', - "value": 'China', - "hash1": '0000ABC3423423523457234ABC34234', - "hash2": '0000ABC3423423523457234ABC34234' - }, - { - "name": 'Document ID', - "value": 'C3451313', - "hash1": '1230ABC3423423523457234ABC34234', - "hash2": '1230ABC3423423523457234ABC34234' - }, - { - "name": 'Document ID', - "value": 'D3451313', - "hash1": '4483ABC3423423523457234ABC34234', - "hash2": '4483ABC3423423523457234ABC34234' - }, - ] - } - ]; - return (
{/* Sidebar */} @@ -112,13 +42,10 @@ const Verify = (() => {
{/* Block */}
- {verifiedData.map((item, index) => ( + {sharedDataStore.sharedData.map((item, index) => (
{/* Header */} -
- - Yesterday at {item.date.slice(-5)} AM - +
{/* Buttons */}
@@ -131,9 +58,8 @@ const Verify = (() => {
{/* Content */}
- {item.fields.map((elem, index) => ( + {item.data.map((elem, index) => (
- {elem.value} - {elem.hash1} - {elem.hash2} + {elem.label} + {elem.value}
- {elem.name}
))} diff --git a/src/store/sharedDataStore.js b/src/store/sharedDataStore.js new file mode 100644 index 0000000..b60ece3 --- /dev/null +++ b/src/store/sharedDataStore.js @@ -0,0 +1,66 @@ +import { makeAutoObservable, reaction } from "mobx"; +import { fetchWrapper } from "../shared/fetchWrapper"; +import { registrationStore } from './store'; + +const labelMap = { + firstname: 'First name', + secondname: 'Second name', + gender: "Gender", + birthdate: "Birthdate", + placeofbirth: "Place of birth", + nationality: "Nationality", + nationalid: "National ID", + nationaldoctype: "National doctype", + nationaldocid: "National doc ID", + nationaldocissuedate: "National doc issue date", + nationaldocexpirydate: "National doc expiry date", + telephone: "Telephone", + twitter: "Twitter", + facebook: "Facebook", + instagram: "Instagram", + youtube: "Youtube", + wechat: "Wechat", + tiktok: "Tiktok", + linkedin: "Linkedin", + vk: "Vk", + github: "Github", + telegram: "Telegram", + qq: "Qq", + snapchat: "Snapchat", + reddit: "Reddit" +}; + +class SharedDataStore{ + _keysArray = []; + _sharedData = []; + + constructor() { + makeAutoObservable(this); + + reaction(() => ({data: registrationStore.keysArray}), ({data}) => { + this._keysArray = data; + this.fetchSharedData(); + }) + } + + fetchSharedData() { + this._keysArray.forEach((elem) => fetchWrapper.get(`http://3.125.47.101/api/data/shared/${elem}`).then((res) => this.changeSharedData(res))) + }; + + changeSharedData(incomingData) { + this._sharedData.push({ + data: incomingData.data, + }) + } + + get sharedData() { + return this._sharedData.map(elem => ({ + data: elem.data.map(item => ({ + label: labelMap[item.label], + value: item.value, + })) + })); + }; +} + +export const sharedDataStore = new SharedDataStore(); \ No newline at end of file diff --git a/src/store/store.js b/src/store/store.js index 82b1c69..a586efa 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -12,6 +12,8 @@ class Store { _userData = {} + _keysArray = [] + _transactionsInfo = {} constructor() { @@ -19,10 +21,16 @@ class Store { this.fetchNodeInfo() + reaction(() => this.tokenKey, () => this.getData()) reaction(() => this.tokenKey, () => this.fetchNewAccountData()) reaction(() => this.tokenKey, () => this.fetchTransactionsInfo()) }; + getData() { + this.fetchNewAccountData(); + this.fetchKeysArray(); + } + fetchNewAccountData() { fetchWrapper.getAuth('http://3.125.47.101/api/data/private', { networkIdentifier: this.nodeInfo.networkIdentifier, @@ -38,6 +46,12 @@ class Store { .then(()=>this.fetchNewAccountData()) } + fetchKeysArray() { + fetchWrapper.getAuth('https://ccab53ea-d042-47b3-b9b4-79b913f47b3d.mock.pstmn.io/data/shared', { + networkIdentifier: this.nodeInfo.networkIdentifier, + lastBlockID: this.nodeInfo.lastBlockID + }).then((res) => this.keysArrayFetchChange(res)) + fetchTransactionsInfo() { fetchWrapper.getAuth(`http://3.125.47.101/api/account/transactions/${this.accountMadeTransaction}?moduleID=1001&assetID=11`, { networkIdentifier: this.nodeInfo.networkIdentifier, @@ -54,8 +68,16 @@ class Store { this._userData = res; } + keysArrayFetchChange(res) { + this._keysArray = res.data; + } + + get keysArray() { + return this._keysArray; + } + get userData() { - return this._userData + return this._userData; } get transactionsInfo() {