Fix meta update process

This commit is contained in:
Spencer Ofwiti
2021-06-15 16:49:26 +00:00
parent 250d44e9a4
commit 2d76f63442
43 changed files with 1451 additions and 516 deletions

View File

@@ -8,3 +8,4 @@ export * from '@app/_helpers/http-getter';
export * from '@app/_helpers/mock-backend';
export * from '@app/_helpers/read-csv';
export * from '@app/_helpers/schema-validation';
export * from '@app/_helpers/sync';

31
src/app/_helpers/sync.ts Normal file
View File

@@ -0,0 +1,31 @@
import { ArgPair, Syncable } from 'cic-client-meta';
import * as Automerge from 'automerge';
export function updateSyncable(
changes: Array<ArgPair>,
changesDescription: string,
syncable: Syncable
): any {
syncable.m = Automerge.change(syncable.m, changesDescription, (m) => {
changes.forEach((c) => {
const path = c.k.split('.');
let target = m['data'];
while (path.length > 1) {
const part = path.shift();
target = target[part];
}
try {
target[path[0]] = c.v;
} catch (error) {
if (
!error.message.includes(
'Cannot assign an object that already belongs to an Automerge document.'
)
) {
throw new Error(error);
}
}
});
m['timestamp'] = Math.floor(Date.now() / 1000);
});
}

View File

@@ -12,7 +12,7 @@ import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp';
import { RegistryService } from '@app/_services/registry.service';
import { CICRegistry } from '@cicnet/cic-client';
import { AuthService } from '@app/_services/auth.service';
import { personValidation, vcardValidation } from '@app/_helpers';
import { personValidation, updateSyncable, vcardValidation } from '@app/_helpers';
import { add0x } from '@src/assets/js/ethtx/dist/hex';
import { KeystoreService } from '@app/_services/keystore.service';
const vCard = require('vcard-parser');
@@ -109,7 +109,7 @@ export class UserService {
for (const prop of Object.keys(accountInfo)) {
update.push(new ArgPair(prop, accountInfo[prop]));
}
syncableAccount.update(update, 'client-branch');
updateSyncable(update, 'client-branch', syncableAccount);
await personValidation(syncableAccount.m.data);
await this.updateMeta(syncableAccount, accountKey, this.headers);
},

View File

@@ -262,17 +262,6 @@
</mat-form-field>
</div>
<div class="col-md-6 col-lg-4">
<button
mat-raised-button
color="primary"
type="button"
class="btn btn-outline-primary mb-3"
>
Add User KYC
</button>
</div>
<div class="col-md-6 col-lg-4">
<button
mat-raised-button
@@ -329,7 +318,7 @@
</thead>
<tbody>
<tr>
<td>{{ account?.vcard?.fn[0].value }}</td>
<td>{{ account?.vcard?.fn[0].value || accountAddress }}</td>
<td>{{ account?.balance | tokenRatio }} {{ tokenSymbol | uppercase }}</td>
<td>{{ account?.date_registered | unixDate }}</td>
<td>

View File

@@ -17,9 +17,9 @@
</ol>
</nav>
<div class="row">
<div class="col-md-6 mb-2">
<div class="col-12 mb-2">
<div class="card">
<mat-card-title class="card-header text-center"> SETTINGS </mat-card-title>
<mat-card-title class="card-header text-center"> ACCOUNT MANAGEMENT </mat-card-title>
<div class="card-body">
<h4>CICADA Admin Credentials</h4>
<span><strong>UserId: </strong> {{ userInfo?.userid }} </span><br />
@@ -27,25 +27,6 @@
<span><strong>Email: </strong> {{ userInfo?.email }} </span>
</div>
<hr />
<div class="card-body">
<h4>Organization Settings</h4>
<a routerLink="/settings/organization"><i>Update your organization settings</i></a>
</div>
</div>
</div>
<div class="col-md-6 mb-2">
<div class="card">
<mat-card-title class="card-header text-center"> ACCOUNT MANAGEMENT </mat-card-title>
<div class="card-body">
<h4>Change Password</h4>
<a routerLink="/settings"><i>Change your account password</i></a>
</div>
<hr />
<div class="card-body">
<h4>Two-step authentication</h4>
<a routerLink="/settings"><i>Secure your account with two step verification</i></a>
</div>
<hr />
<div class="card-body">
<button
mat-raised-button
@@ -59,8 +40,8 @@
</div>
</div>
</div>
<div class="col-12">
<div class="card mb-3">
<div class="col-12 mb-2">
<div class="card">
<mat-card-title class="card-header">
<div class="row">
TRUSTED USERS

View File

@@ -40,12 +40,12 @@
<span> Settings </span>
</a>
</li>
<li>
<a routerLink="/admin" routerLinkActive="active" appMenuSelection>
<i class="fa fa-user-secret"></i>
<span> Admin </span>
</a>
</li>
<!-- <li>-->
<!-- <a routerLink="/admin" routerLinkActive="active" appMenuSelection>-->
<!-- <i class="fa fa-user-secret"></i>-->
<!-- <span> Admin </span>-->
<!-- </a>-->
<!-- </li>-->
</ul>
</nav>
</div>