Skip to content

Commit

Permalink
APP-193: run follow trust always with the primary user and not with t…
Browse files Browse the repository at this point in the history
…he orgas
  • Loading branch information
jaensen committed Mar 25, 2023
1 parent ad654da commit 78735c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
34 changes: 25 additions & 9 deletions shell/src/shared/followTrust.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
CompareTrustRelationsDocument,
CompareTrustRelationsQueryVariables,
CompareTrustRelationsResult,
Profile
CompareTrustRelationsResult, Profile, ProfileByIdDocument, ProfileByIdQueryVariables
} from "./api/data/types";
import {me} from "./stores/me";
import {ApiClient} from "./apiConnection";
import {fSetTrust} from "../dapps/o-banking/processes/setTrust";
import {Environment} from "./environment";
import {getSessionInfo} from "../dapps/o-passport/processes/identify/services/getSessionInfo";

export class FollowTrust {

Expand All @@ -28,6 +27,9 @@ export class FollowTrust {
}

reset(interval?:number) {
if (!interval) {
interval = FollowTrust.shortIntervalInMilliseconds;
}
console.log(`Resetting FollowTrust to ${interval == FollowTrust.longIntervalInMilliseconds ? 'long' : 'short'} interval.`);
this.stop();
this.intervalInMilliseconds = interval ? interval : FollowTrust.shortIntervalInMilliseconds;
Expand All @@ -49,7 +51,7 @@ export class FollowTrust {
.then((transactionHash) => {
if (transactionHash) {
console.log(`FollowTrust is done: (transactionHash: ${transactionHash}). Using short interval.`);
this.reset(FollowTrust.shortIntervalInMilliseconds);
this.reset();
} else {
console.log(`FollowTrust is done. Currently no trust changes. Using long interval.`);
this.reset(FollowTrust.longIntervalInMilliseconds);
Expand All @@ -74,17 +76,31 @@ export class FollowTrust {
}

private async followTrust() {
let $me: Profile;
me.subscribe((me) => $me = me)();
console.log(`FollowTrust is running for ${$me?.circlesAddress}`);
// Either use the selected profile (which will be usually an orge) ..
// let $me: Profile;
// me.subscribe((me) => $me = me)();
// .. or use the sessionInfo (which will always a person)
const sessionInfo = await getSessionInfo();
if (!sessionInfo.profileId) {
console.log(`FollowTrust is not running because there is no profile in sessionInfo.`);
}

const profile = await ApiClient.query<Profile[], ProfileByIdQueryVariables>(ProfileByIdDocument, {
id: sessionInfo.profileId
});
if (!profile.length) {
console.log(`FollowTrust is not running because there is no profile with id ${sessionInfo.profileId}.`);
}

console.log(`FollowTrust is running for ${profile[0]?.circlesAddress}`);

if (!$me) {
if (!profile) {
throw new Error(`$me is not yet initialized.`);
}

try {
const diff = await ApiClient.query<CompareTrustRelationsResult, CompareTrustRelationsQueryVariables>(CompareTrustRelationsDocument, {
canSendTo: $me.circlesAddress,
canSendTo: profile[0].circlesAddress,
compareWith: []
});

Expand Down
1 change: 1 addition & 0 deletions shell/src/shared/stores/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const _me = readable<Profile | null>(null, function start(set) {
set(event.profile);
console.log("me.ts new $me: ", event.profile);
localStorage.setItem("me", JSON.stringify(event.profile));
FollowTrust.instance.reset();
}
}
);
Expand Down

0 comments on commit 78735c0

Please sign in to comment.