Skip to content

Commit

Permalink
Add possibility in getLatest to get mutual activity by providing othe…
Browse files Browse the repository at this point in the history
…rSafeAddress
  • Loading branch information
mikozet committed Jul 30, 2023
1 parent 2d1756f commit 99accfa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
24 changes: 14 additions & 10 deletions src/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ export default function createActivityModule(web3, contracts, utils) {
`;

parameters = `
orderBy: "time",
orderDirection: "desc",
orderBy: "time",
orderDirection: "desc",
first: ${options.limit},
skip: ${options.offset},
where: {
skip: ${options.offset},
where: {
or: [
${
filterString === TYPE_TRUST || !filterString
? mutualTrustParams
: ''
}
${
filterString === TYPE_TRANSFER || !filterString
? mutualTransferParams
: ''
},
${
filterString === TYPE_TRUST || !filterString
? mutualTrustParams
: ''
}
]
}
Expand Down Expand Up @@ -255,7 +255,11 @@ export default function createActivityModule(web3, contracts, utils) {

// Filter transfer events which are not UBI payout as we have them
// covered through HUB_TRANSFER events
if (type === ActivityTypes.TRANSFER && data.from !== ZERO_ADDRESS) {
if (
type === ActivityTypes.TRANSFER &&
data.from !== ZERO_ADDRESS &&
options.otherSafeAddress === ZERO_ADDRESS
) {
return acc;
}

Expand Down
29 changes: 20 additions & 9 deletions test/activity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ describe('Activity', () => {
});

mutualActivities = mutualLatest.activities;
//mutualActivities.map((a) => console.log('mutual - ', a));
});

it('orders the activities by timestamp', () => {
Expand All @@ -109,7 +108,7 @@ describe('Activity', () => {
});
});

xit('filters them by type', async () => {
it('filters them by type', async () => {
const result = await core.activity.getLatest(account, {
safeAddress,
filter: core.activity.ActivityFilterTypes.TRANSFERS,
Expand All @@ -126,12 +125,24 @@ describe('Activity', () => {
});

it('return mutual activities', async () => {
//console.log("MUTUAL RESULT ", mutualActivities);
expect(mutualActivities.length).toBe(2); // tmp test - this is not actually expected
});

expect(mutualActivities.length).toBe(5); // tmp test - this is not actually expected
it('returns mutual activities connected with trust action', async () => {
const foundTransferItems = mutualActivities.filter(
(item) => item.type === core.activity.ActivityTypes.TRANSFER,
);
expect(foundTransferItems.length).toEqual(1);
});

it('returns mutual activities connected with transfer action', async () => {
const foundTrustItems = mutualActivities.filter(
(item) => item.type === core.activity.ActivityTypes.ADD_CONNECTION,
);
expect(foundTrustItems.length).toEqual(1);
});

xit('returns activities based on pagination arguments', async () => {
it('returns activities based on pagination arguments', async () => {
const transactionHash = await addSafeOwner(core, account, {
safeAddress,
ownerAddress: thirdOwnerAccount.address,
Expand Down Expand Up @@ -170,7 +181,7 @@ describe('Activity', () => {
expect(activity).toBeUndefined();
});

xit('returns the first added owner event', async () => {
it('returns the first added owner event', async () => {
const activity = activities.find(({ type, data }) => {
return (
type === core.activity.ActivityTypes.ADD_OWNER &&
Expand All @@ -182,7 +193,7 @@ describe('Activity', () => {
expect(activity).toBeDefined();
});

xit('returns the second added owner event', async () => {
it('returns the second added owner event', async () => {
const activity = activities.find(({ type, data }) => {
return (
type === core.activity.ActivityTypes.ADD_OWNER &&
Expand All @@ -194,7 +205,7 @@ describe('Activity', () => {
expect(activity).toBeDefined();
});

xit('returns the trust event for both Safes', async () => {
it('returns the trust event for both Safes', async () => {
const query = ({ type, data }) => {
return (
type === core.activity.ActivityTypes.ADD_CONNECTION &&
Expand All @@ -207,7 +218,7 @@ describe('Activity', () => {
expect(otherActivities.find(query)).toBeDefined();
});

xit('returns the hub transfer event for both Safes', async () => {
it('returns the hub transfer event for both Safes', async () => {
const query = ({ type, data }) => {
return (
type === core.activity.ActivityTypes.HUB_TRANSFER &&
Expand Down

0 comments on commit 99accfa

Please sign in to comment.