Add account object interface.

Add new vcard parser.
This commit is contained in:
Spencer Ofwiti 2021-03-02 10:29:14 +03:00
parent 2491dc54a0
commit 0d7f4aae13
9 changed files with 81 additions and 48 deletions

11
package-lock.json generated
View File

@ -35,6 +35,7 @@
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"vcard-parser": "^1.0.0",
"vcards-js": "^2.10.0",
"web3": "^1.3.0",
"zone.js": "~0.10.2"
@ -18089,6 +18090,11 @@
"node": ">= 0.8"
}
},
"node_modules/vcard-parser": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/vcard-parser/-/vcard-parser-1.0.0.tgz",
"integrity": "sha512-rSEjrjBK3of4VimMR5vBjLLcN5ZCSp9yuVzyx5i4Fwx74Yd0s+DnHtSit/wAAtj1a7/T/qQc0ykwXADoD0+fTQ=="
},
"node_modules/vcards-js": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/vcards-js/-/vcards-js-2.10.0.tgz",
@ -35411,6 +35417,11 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"vcard-parser": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/vcard-parser/-/vcard-parser-1.0.0.tgz",
"integrity": "sha512-rSEjrjBK3of4VimMR5vBjLLcN5ZCSp9yuVzyx5i4Fwx74Yd0s+DnHtSit/wAAtj1a7/T/qQc0ykwXADoD0+fTQ=="
},
"vcards-js": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/vcards-js/-/vcards-js-2.10.0.tgz",

View File

@ -39,6 +39,7 @@
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"vcard-parser": "^1.0.0",
"vcards-js": "^2.10.0",
"web3": "^1.3.0",
"zone.js": "~0.10.2"

View File

@ -0,0 +1,7 @@
import { Account } from './account';
describe('Account', () => {
it('should create an instance', () => {
expect(new Account()).toBeTruthy();
});
});

View File

@ -0,0 +1,52 @@
export interface AccountDetails {
date_registered: number;
gender: string;
identities: {
evm: {
'bloxberg:8996': string[];
'oldchain:1': string[];
}
};
location: {
area_name: string;
};
products: string[];
vcard: {
email: [{
value: string;
}];
fn: [{
value: string;
}];
n: [{
value: string[];
}];
tel: [{
meta: {
TYP: string[];
},
value: string;
}],
version: [{
value: string;
}];
};
}
export interface Signature {
algo: string;
data: string;
digest: string;
engine: string;
}
export interface Meta {
data: AccountDetails;
id: string;
signature: Signature;
}
export interface MetaResponse {
id: string;
m: Meta;
}

View File

@ -1,3 +1,4 @@
export * from '@app/_models/transaction';
export * from '@app/_models/settings';
export * from '@app/_models/user';
export * from '@app/_models/account';

View File

@ -5,7 +5,7 @@ import {environment} from '@src/environments/environment';
import {first} from 'rxjs/operators';
import {AccountIndex, MutableKeyStore, MutablePgpKeyStore, PGPSigner, Signer} from '@app/_helpers';
import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta';
import {parse} from '@src/assets/js/parse-vcard';
const vCard = require('vcard-parser');
@Injectable({
providedIn: 'root'
@ -16,6 +16,7 @@ export class UserService {
signer: Signer = new PGPSigner(this.keystore);
accountIndexQuery = new AccountIndex(environment.contractAddress);
accountsMeta = [];
accounts: any = [];
private accountsList = new BehaviorSubject<any>(this.accounts);
accountsSubject = this.accountsList.asObservable();
@ -155,8 +156,10 @@ export class UserService {
const accountAddresses = await this.accountIndexQuery.last(await this.accountIndexQuery.totalAccounts());
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
this.getAccountDetailsFromMeta(await User.toKey(accountAddress)).pipe(first()).subscribe(res => {
const accountInfo = Envelope.fromJSON(JSON.stringify(res)).unwrap().m.data;
accountInfo.vcard = parse(atob(accountInfo.vcard));
const account = Envelope.fromJSON(JSON.stringify(res)).unwrap();
this.accountsMeta.push(account);
const accountInfo = account.m.data;
accountInfo.vcard = vCard.parse(atob(accountInfo.vcard));
this.accounts.push(accountInfo);
this.accountsList.next(this.accounts);
});

View File

@ -54,12 +54,12 @@
matSortDirection="desc" matSortDisableClear>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> NAME </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user?.vcard.fn}} </mat-cell>
<mat-cell *matCellDef="let user"> {{user?.vcard.fn[0].value}} </mat-cell>
</ng-container>
<ng-container matColumnDef="phone">
<mat-header-cell *matHeaderCellDef mat-sort-header> PHONE NUMBER </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user?.vcard.tel[0].value[0]}} </mat-cell>
<mat-cell *matCellDef="let user"> {{user?.vcard.tel[0].value}} </mat-cell>
</ng-container>
<ng-container matColumnDef="created">

View File

@ -14,7 +14,7 @@ import {Router} from '@angular/router';
export class AccountsComponent implements OnInit {
dataSource: MatTableDataSource<any>;
accounts: any[] = [];
displayedColumns = ['name', 'phone', 'created', 'balance', 'type', 'status', 'location', 'failedPinAttempts', 'select'];
displayedColumns = ['name', 'phone', 'created', 'location', 'select'];
initialSelection = [];
allowMultiSelect = true;
selection: SelectionModel<any>;

View File

@ -1,42 +0,0 @@
export function parse(input) {
const Re1 = /^(version|fn|title|org):(.+)$/i;
const Re2 = /^([^:;]+);([^:]+):(.+)$/;
const ReKey = /item\d{1,2}\./;
let fields = {};
input.split(/\r\n|\r|\n/).forEach(function (line) {
let results, key;
if (Re1.test(line)) {
results = line.match(Re1);
key = results[1].toLowerCase();
fields[key] = results[2];
} else if (Re2.test(line)) {
results = line.match(Re2);
key = results[1].replace(ReKey, '').toLowerCase();
let meta = {};
results[2].split(';')
.map(function (p, i) {
const match = p.match(/([a-z]+)=(.*)/i);
if (match) {
return [match[1], match[2]];
} else {
return ["TYPE" + (i === 0 ? "" : i), p];
}
})
.forEach(function (p) {
meta[p[0]] = p[1];
});
if (!fields[key]) fields[key] = [];
fields[key].push({
meta: meta,
value: results[3].split(';')
})
}
});
return fields;
}