Merge pull request #25 from franze6/DID-4

Did 4
This commit is contained in:
DuCay
2022-06-30 13:35:58 +03:00
committed by GitHub
3 changed files with 29 additions and 10 deletions

View File

@@ -11,9 +11,9 @@ const Onboarding2 = observer(()=>{
const [dataRegistration, setDataRegistration] = useState(
{
first_name: '',
last_name: '',
second_name: '',
gender: '',
date_birth: '',
birthdate: '',
}
)
const [fillingForm, setFillingForm] = useState(false)
@@ -107,8 +107,8 @@ const Onboarding2 = observer(()=>{
<input id="first_name" onChange={(event)=>saveValueChange(event)} className="form-input w-full" type="text" />
</div>
<div>
<label className="block text-sm font-medium mb-1" htmlFor="last_name">Last name <span className="text-rose-500">*</span></label>
<input id="last_name" onChange={(event)=>saveValueChange(event)} className="form-input w-full" type="text" />
<label className="block text-sm font-medium mb-1" htmlFor="second_name">Last name <span className="text-rose-500">*</span></label>
<input id="second_name" onChange={(event)=>saveValueChange(event)} className="form-input w-full" type="text" />
</div>
<div>
<label className="block text-sm font-medium mb-1" htmlFor="gender">Gender <span className="text-rose-500">*</span></label>
@@ -119,8 +119,8 @@ const Onboarding2 = observer(()=>{
</select>
</div>
<div>
<label className="block text-sm font-medium mb-1" htmlFor="date_birth">Date of birth <span className="text-rose-500">*</span></label>
<input id="date_birth" onChange={(event)=>saveValueChange(event)} className="form-input w-full" type="date" autoComplete="on" />
<label className="block text-sm font-medium mb-1" htmlFor="birthdate">Date of birth <span className="text-rose-500">*</span></label>
<input id="birthdate" onChange={(event)=>saveValueChange(event)} className="form-input w-full" type="date" autoComplete="on" />
</div>
</div>
<div className="flex items-center justify-between mt-6">

View File

@@ -9,11 +9,12 @@ const Onboarding4 = observer(()=>{
const [checkBoxesSelected, setCheckBoxesSelected] = useState(false)
function validateCheckBox () {
function createAccount () {
let checkBoxes=[...document.getElementsByClassName("form-checkbox")]
if(checkBoxes.find(item=>item.checked===false)) {
return
} else {
registrationStore.fetchCreateNewAccount()
setCheckBoxesSelected(true)
}
@@ -81,7 +82,7 @@ const Onboarding4 = observer(()=>{
<path className="text-emerald-500" d="m28.5 41-8-8 3-3 5 5 12-12 3 3z" />
</svg>
<h1 className="text-3xl text-slate-800 font-bold mb-8">{registrationStore.accountData.first_name ? `Nice to meet you, ${registrationStore.accountData.first_name} 🙌` : 'Please, go back step 2'}</h1>
<button onClick={()=>validateCheckBox()} className="btn px-6 bg-indigo-500 hover:bg-indigo-600 text-white">
<button onClick={()=>createAccount()} className="btn px-6 bg-indigo-500 hover:bg-indigo-600 text-white">
<Link id="link-dashboard" to={checkBoxesSelected && "/dashboard"}>Go To Profile -&gt;</Link>
</button>
</div>

View File

@@ -21,6 +21,14 @@ class Store {
}))
};
fetchCreateNewAccount() {
fetchWrapper.postAuth('http://3.125.47.101/api/data/account', {
networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID
}, [...this.encryptAccountData])
.catch(()=>{})
}
savePassPhrase(phrase) {
this._passPhrase = phrase
}
@@ -37,7 +45,6 @@ class Store {
fetchNodeInfoSuccess(info) {
this._nodeInfo = info.data;
console.log(info)
}
fetchNodeInfoFailed(err) {
@@ -52,6 +59,17 @@ class Store {
return this._accountData
};
get encryptAccountData() {
return Object.keys(this.accountData).map((label) => {
let value = cryptography.encryptMessageWithPassphrase(cryptography.getRandomBytes(32).toString('hex') + ":" + this.accountData[label], this.passPhrase, this.pubKey);
return {
"label": label,
"value": value.encryptedMessage,
"value_nonce": value.nonce,
}
})
}
get nodeInfo() {
return this._nodeInfo;
}
@@ -69,7 +87,7 @@ class Store {
}
get tokenKey() {
const stringToSign = this.nodeInfo.networkIdentifier.concat(this.nodeInfo.lastBlockID);
const stringToSign = this.nodeInfo.networkIdentifier + this.nodeInfo.lastBlockID;
if(!stringToSign)
return '';
const sign = cryptography.signDataWithPassphrase(Buffer.from(stringToSign, 'hex'), this.passPhrase).toString('hex')