Commit 8cf91290 authored by Mark Harding's avatar Mark Harding

(chore): cleanup tasks

parent 45d7a3ea
No related merge requests found
......@@ -36,10 +36,7 @@
>
<t3-tree></t3-tree>
</div>
<div
class="view--vote"
*ngIf="(verificationService.profile$ | async) || true"
>
<div class="view--vote" *ngIf="verificationService.profile$ | async">
<!-- Trust component-->
<t3-trust></t3-trust>
</div>
......
......@@ -10,7 +10,7 @@ declare const Connect: any;
})
export class AppComponent {
title = "t3";
view: string = "vote"; // ! TODO later: this should be 'unlock'
view: string = "unlock"; // ! TODO later: this should be 'unlock'
constructor(public verificationService: uPortVerificationService) {}
......
......@@ -2,30 +2,48 @@ import { Injectable, Inject } from "@angular/core";
import { WEB3 } from "../web3/web3.module";
import * as TrustContract from "../web3/contracts/trust.contract";
import { BehaviorSubject } from "rxjs";
import defaults from "./trust.map";
@Injectable()
export class T3TrustTraversalService {
from: string;
trusts$: BehaviorSubject<any[]> = new BehaviorSubject([]);
trustsRaw$: BehaviorSubject<any[]> = new BehaviorSubject([]);
trusts$ = this.trustsRaw$.pipe();
trustMap: Map<string, any> = new Map();
constructor(@Inject(WEB3) private web3) {}
async fetchFromEthereum(from: string) {
async fetchFromEthereum(from: string, degree = 1) {
const contract = new this.web3.eth.Contract(
TrustContract.ABI,
TrustContract.ADDRESS
);
const trusts = await contract.methods.getTrusts(from).call();
let add = [];
for (const trust of trusts) {
add.push({
from_did: "did:eth:" + trust.from,
to_did: "did:eth:" + trust.to,
score: trust.score
const entity_did = "did:ethr:" + trust.from.toLowerCase();
const actor_did = "did:ethr:" + trust.to.toLowerCase();
let score = trust.score;
const { name, avatar } = defaults.get(actor_did);
if (this.trustMap.has(actor_did)) {
const current = this.trustMap.get(actor_did);
if (score > 0) {
score = current.score + score / current.degree;
}
if (score < 0) {
score = current.score - score / current.degree;
}
}
this.trustMap.set(actor_did, {
entity_did,
actor_did,
score,
degree,
name,
avatar
});
this.fetchFromEthereum(trust.to);
this.fetchFromEthereum(trust.to, degree + 1);
}
this.trusts$.next(add);
console.log("eth says", add);
this.trustsRaw$.next(Array.from(this.trustMap.values()));
}
}
<h1>Do you trust this person?</h1>
<ng-container *ngFor="let user of users; let i = index">
<div *ngIf="i === currentIndex">
<div *ngIf="i === currentIndex && user">
<!-- [@slowFadeAnimation]="isPaging ? 'out' : 'in'" -->
<div class="userName">{{ user.name }}</div>
<!-- BUTTONS -->
......@@ -56,9 +56,6 @@
</div>
<!-- SCORE -->
<div class="scoreWrapper">
<div class="score">
{{ user.score | number: '0.1-3' | percent }}
</div>
<!-- METRICS -->
<div class="metricsWrapper">
<!-- THERMOMETER -->
......@@ -68,7 +65,9 @@
<!-- [@pointerSlideAnimation]="!hasRecalculated ? 'current' : 'new'" -->
<div class="pointerWrapper">
<i class="material-icons pointer" [style.left.%]="user.score * 94"
<i
class="material-icons pointer"
[style.left.%]="trustService.getScore(user) * 94"
>arrow_drop_up</i
>
</div>
......@@ -77,7 +76,7 @@
<!-- SCORE -->
<div class="scoreWrapper">
<div class="score">
{{ user.score | number: '0.1-3' | percent }}
{{ trustService.getScore(user) | number: "0.1-3" | percent }}
</div>
<div class="scoreSubtitle">Trustworthy</div>
</div>
......
......@@ -8,7 +8,7 @@ import {
} from "@angular/animations";
import { T3TrustService } from "./trust.service";
import { T3TrustTraversalService } from "./traversal.service";
import data from "./trust.fake";
import data from "./trust.defaults";
@Component({
selector: "t3-trust",
......@@ -49,9 +49,7 @@ export class T3TrustComponent implements OnInit, OnDestroy {
hasRecalculated: boolean = false;
isPaging: boolean = false;
trustTreeRaw: Array<any> = [];
finalTrustTree: Array<any> = [];
users = data;
users;
usersNew: Array<any> = []; //!!
......@@ -61,19 +59,24 @@ export class T3TrustComponent implements OnInit, OnDestroy {
) {}
ngOnInit() {
console.log(data);
this.traversalService.fetchFromEthereum(
"0x3e010d48eeE73c9f545591C52E3bD23a7340A91F"
"0x6afd852ac0a9bf29e2841453531bba322908732e"
);
this.finalTrustTree = this.trustService.getTrustTree("1");
console.log(this.finalTrustTree);
this.actorDid = this.users[0].did;
this.traversalService.trusts$.subscribe(trusts => {
this.users = trusts;
//if (!this.user) {
this.user = this.users[0];
this.lastIndex = this.users.length - 1;
//}
});
// this.actorDid = this.users[0].from_did;
this.user = this.users[0];
// this.user = this.users[0];
this.currentIndex = 0;
this.hasVotedOnUser = this.user.vote ? true : false;
this.currentScore = this.user.score;
// this.hasVotedOnUser = this.user.vote ? true : false;
// this.currentScore = this.user.score;
this.lastIndex = this.users.length - 1;
}
......@@ -95,7 +98,7 @@ export class T3TrustComponent implements OnInit, OnDestroy {
}
this.hasVotedOnUser = true;
this.hasVotedOnUserThisSession = true;
this.user.vote = vote;
this.user.score = vote;
this.recalculateScore();
}
......@@ -103,7 +106,7 @@ export class T3TrustComponent implements OnInit, OnDestroy {
this.hasVotedOnUser = true;
this.hasRecalculated = true;
this.newScore = 0.88; // ! should be calculated
this.newScore = 1; // ! should be calculated
this.user.score = this.newScore;
if (this.sliderTimeout) {
......
export default [
{
name: "Homer Simpson",
avatar: "/assets/homer.png",
did: "did:ethr:0x3e010d48eee73c9f545591c52e3bd23a7340a91f"
},
{
name: "Marge Simpson",
avatar: "/assets/marge.png",
did: "did:ethr:0x004aacab4da0dae5220fb3e5b99e41097f8c9417"
},
{
name: "Bart Simpson",
avatar: "/assets/bart.png",
did: "did:ethr:0x3b983ef216efc937718a0aa085b4f2ffce643132"
},
{
name: "Lisa Simpson",
avatar: "/assets/lisa.png",
did: "did:ethr:0x92e051b3527718fae161e88b495e3ef75b4e48d1"
},
{
name: "Maggie Simpson",
avatar: "/assets/maggie.png",
did: "did:ethr:0x37b79eaa6fc33519de02b58083231b6be26dbc40"
},
{
name: "Santa's Little Helper",
avatar: "/assets/santasLittleHelper.png",
did: "did:ethr:0x41a032e4e6e19d68614cadc8fd23bd437c23450b"
},
{
name: "Snowball II/V",
avatar: "/assets/snowball.png",
did: "did:ethr:0x5685a04f8524220860669128a11d4aed6cdf529e"
},
{
name: "Abraham Simpson",
avatar: "/assets/Grampa.png",
did: "did:ethr:0xb979ab1d64f850249641af7599662321461041b3"
},
{
name: "Apu Nahasapeemapetilon",
avatar: "/assets/apu.png",
did: "did:ethr:0xf01f4e54a5d9bb53d0cbe955899eb3ad348fab01"
},
{
name: "Barney Gumble",
avatar: "/assets/barney.png",
did: "did:ethr:0x91eb2563f8d0d359b5e2ff3922a3f4ec69d37b26"
},
{
name: "Bleeding Gums Murphy",
avatar: "/assets/bleedingGums.png",
did: "did:ethr:0x06a9f2ca4ce800b614e171da3bde8b5a29f0fd89"
},
{
name: "Chief Clancy Wiggum",
avatar: "/assets/chief.png",
did: "did:ethr:0xff3d65b2dc6f356f00ad36dd44d25107b63bc9fb"
},
{
name: "Dewey Largo",
avatar: "/assets/deweyLargo.png",
did: "did:ethr:0x1935ee777be794bbc26b3b4bbcc6951922fc04af"
},
{
name: "Eddie",
avatar: "/assets/eddie.png",
did: "did:ethr:0x7a6729affaaedb24c68028192287fb549f305575"
},
{
name: "Edna Krabappel",
avatar: "/assets/edna.png",
did: "did:ethr:0x1af1a2dfc69c477542d816e76158bd6c79801269"
},
{
name: "Itchy",
avatar: "/assets/itchy.png",
did: "did:ethr:0x60409600114557488900d39f62d6f477bb405eeb"
},
{
name: "Janey Powell",
avatar: "/assets/janey.png",
did: "did:ethr:0x6109a92979a1d0126389f8da00681f30a3ac544e"
},
{
name: "Jasper Beardsley",
avatar: "/assets/beardsley.png",
did: "did:ethr:0xea9a12928547c33d27ee435f5ca2b9582beaa66b"
},
{
name: "Kent Brockman",
avatar: "/assets/brockman.png",
did: "did:ethr:0xfa4f44357ef93909bb1697915cd39afbb6259db8"
},
{
name: "Krusty The Clown",
avatar: "/assets/krusty.png",
did: "did:ethr:0xa1e7fbb91122cbe80afa288b25aaa615e1d8fd38"
},
{
name: "Lenny Leonard",
avatar: "/assets/lenny.png",
did: "did:ethr:0x8d6e0709f6677b66f6f82a0225f507542d29f5d6"
},
{
name: "Lou",
avatar: "/assets/lou.png",
did: "did:ethr:0x0ef0c4f2b0c1ed96ac8efa3eb4c25b8f54e99e63"
},
{
name: "Martin Prince",
avatar: "/assets/martin.png",
did: "did:ethr:0x0f0f5587637660f966797db8f72dbe5d99560768"
},
{
name: "Marvin Monroe",
avatar: "/assets/marvin.png",
did: "did:ethr:0xc691eb3c4e5cee6ffdb954ade14aedf29ff747e6"
},
{
name: "Milhouse Van Houten",
avatar: "/assets/milhouse.png",
did: "did:ethr:0x37502a09751ae6fe827a166db4ba0805812bf360"
},
{
name: "Moe Szyslak",
avatar: "/assets/moe.png",
did: "did:ethr:0x06846a4e3879374d8a28b19fb680750ba8def2a7"
},
{
name: "Mr. Burns",
avatar: "/assets/burns.png",
did: "did:ethr:0xa163ff521e47bffcca12b87274db7db4bb8cfbbc"
},
{
name: "Ned Flanders",
avatar: "/assets/flanders.png",
did: "did:ethr:0xa0a872594d34efaf1cc15979cef1fd7945989357"
},
{
name: "Otto Mann",
avatar: "/assets/otto.png",
did: "did:ethr:0xfb35d6a595698d11b2edc74be285b137da862f2a"
},
{
name: "Patty Bouvier",
avatar: "/assets/patty.png",
did: "did:ethr:0xa66d1dcbae93f0f8a8492fea2cad52c21f5c863d"
},
{
name: "Ralph Wiggum",
avatar: "/assets/ralph.png",
did: "did:ethr:0xe436aad18c8473cee19f4a290afb00fd81eac5eb"
},
{
name: "Reverend Timothy Lovejoy",
avatar: "/assets/lovejoy.png",
did: "did:ethr:0x848434682c78f0391641b4575f5734888608796d"
},
{
name: "Scratchy",
avatar: "/assets/scratchy.png",
did: "did:ethr:0x85d24de072b295a4552e302e55b466b7cadad69c"
},
{
name: "Selma Bouvier",
avatar: "/assets/selma.png",
did: "did:ethr:0x36e3a6e723fecdd28f8aee5b18dd110f54e411aa"
},
{
name: "Seymour Skinner",
avatar: "/assets/skinner.png",
did: "did:ethr:0x0210c3a8c0be047b65cb16b12c3e65f682556585"
},
{
name: "Sherri",
avatar: "/assets/sherri.png",
did: "did:ethr:0xb761469b6093edfeb5bf7515e929750f52be8650"
},
{
name: "Terri",
avatar: "/assets/terri.png",
did: "did:ethr:0x19574d2965ed5fb9277f26d313543ec49f1e580c"
},
{
name: "Sideshow Bob",
avatar: "/assets/sideshowBob.png",
did: "did:ethr:0x555b21efaa2ee3ca666f8e5d10938b07d2ef5dff"
}
];
import dids from "./trust.defaults";
const defaults: Map<string, any> = new Map();
for (const did of dids) {
defaults.set(did.did.toLowerCase(), did);
}
export default defaults;
import { Injectable, Inject } from '@angular/core';
import { Observable } from 'rxjs';
import { WEB3 } from '../web3/web3.module';
import * as TrustContract from '../web3/contracts/trust.contract';
import { HttpClient } from '@angular/common/http';
import { uPortVerificationService } from '../uport/verification.service';
import { first } from 'rxjs/operators';
import { Injectable, Inject } from "@angular/core";
import { Observable } from "rxjs";
import { WEB3 } from "../web3/web3.module";
import * as TrustContract from "../web3/contracts/trust.contract";
import { HttpClient } from "@angular/common/http";
import { uPortVerificationService } from "../uport/verification.service";
import { first } from "rxjs/operators";
const T3_SERVER_URI = 'https://t3-backend.ngrok.io';
const T3_SERVER_URI = "https://t3-backend.ngrok.io";
@Injectable()
export class T3TrustService {
......@@ -20,150 +20,33 @@ export class T3TrustService {
.pipe(first())
.toPromise();
this.http
.post(T3_SERVER_URI + '/vote', {
.post(T3_SERVER_URI + "/vote", {
profile,
to: obj.did.split(':')[2],
to: obj.did.split(":")[2],
score: obj.score
})
.subscribe(data => {});
}
getTrustTree(actorDid: string) {
let penultimateTrustTree: Array<any> = [];
let finalTrustTree: Array<any> = [];
// END STRUCTURE
// [
// {
// actor_did: '1',
// entity_did: '2',
// vote: 1,
// degree: 1
// },
// {
// actor_did: '1',
// entity_did: '3',
// vote: 0,
// degree: 2
// },
// {...},
// {...},
// {...},
// {...},
// {...},
// {...},
// {...}
// ]
// QUERY FAKE DB
const fakeResponse = this.getBlockchainResponse(actorDid);
const fakeResponseWithAllDidsArray = this.makeAllDidsArray(fakeResponse);
// ROUND 1
// Do the processing for each did in allDids[];
// PROCESS BLOCKCHAIN RESPONSE
// fakeResponse.forEach(function(value) {
// const tempArray = value.split(':');
// this.currentActorObj.allDids.push(tempArray[1]);
// switch (tempArray[2]) {
// case '1':
// currentActorObj.trustedDids.push(tempArray[2]);
// break;
// case '0':
// currentActorObj.neutralDids.push(tempArray[2]);
// break;
// case '-1':
// currentActorObj.distrustedDids.push(tempArray[2]);
// }
// });
// AFTER CURRENTACTOROBJ is populated,
// add all
// go through each actor in network[] and get their network
console.log('finalTrustTree');
console.log(finalTrustTree);
return finalTrustTree;
}
makeAllDidsArray(fakeResponse) {
const newFakeResponse = fakeResponse;
console.log(newFakeResponse[0].blockchainResponse);
// let allDids: Array<any> = [];
let allDids = newFakeResponse[0].blockchainResponse.trustedDids;
// .concat(newFakeResponse[0].blockchainResponse.NeutralDids)
// .concat(newFakeResponse[0].blockchainResponse.DistrustedDids);
allDids = allDids.concat(newFakeResponse[0].blockchainResponse.NeutralDids);
allDids = allDids.concat(
newFakeResponse[0].blockchainResponse.DistrustedDids
);
console.log('allDids');
console.log(allDids);
return newFakeResponse;
}
getBlockchainResponse(actorDid: string) {
const fakeDatabase = [
{
actorDid: '1',
blockchainResponse: {
trustedDids: ['2'],
neutralDids: ['3'],
distrustedDids: ['4']
}
},
{
actorDid: '2',
blockchainResponse: {
trustedDids: ['1', '3', '5'],
neutralDids: ['4'],
distrustedDids: []
}
},
{
actorDid: '3',
blockchainResponse: {
trustedDids: ['1'],
neutralDids: ['4', '5'],
distrustedDids: ['2']
}
},
{
actorDid: '4',
blockchainResponse: {
trustedDids: ['3'],
neutralDids: ['1'],
distrustedDids: ['2', '5']
}
},
{
actorDid: '5',
blockchainResponse: {
trustedDids: ['3', '6'],
neutralDids: ['2'],
distrustedDids: ['4']
}
},
{
actorDid: '6',
blockchainResponse: {
trustedDids: [],
neutralDids: ['3'],
distrustedDids: ['7', '8']
}
}
];
// tslint:disable-next-line: only-arrow-functions
let result = fakeDatabase.filter(function(item) {
return item.actorDid === actorDid;
});
return result;
getScore(user) {
// let score = 0.5;
// switch (parseInt(user.score)) {
// case 1:
// score = 1 / user.degree;
// break;
// case 0:
// break;
// case -1:
// score = 0.01 * user.degree;
// break;
// }
let score = user.score / user.degree;
if (score > 1) {
score = 1;
}
if (score < 0) {
score = 0;
}
return score;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment