Skip to content

Commit

Permalink
Merge pull request #13 from GeneralMagicio/4-removeRecurringDonation
Browse files Browse the repository at this point in the history
remove recurring donation codes
  • Loading branch information
aminlatifi authored Aug 12, 2024
2 parents e406ca0 + 670bd36 commit d57dfee
Show file tree
Hide file tree
Showing 57 changed files with 38 additions and 8,471 deletions.
25 changes: 3 additions & 22 deletions .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_S3_REGION }}

- name: Download latest DB backup from S3
run: |
FILENAME=$(aws s3 ls ${{ secrets.AWS_S3_BUCKET_PATH_STAGING }}/ | sort | tail -n 1 | awk '{print $4}')
aws s3 cp ${{ secrets.AWS_S3_BUCKET_PATH_STAGING }}/$FILENAME /tmp/db_backup.zip
- name: Unzip DB backup
run: |
unzip /tmp/db_backup.zip -d /tmp
mv /tmp/backups/givethio-staging/*.sql /tmp/backups/givethio-staging/db_backup.sql

- name: Wait for PostgreSQL to become ready
run: |
Expand All @@ -94,9 +78,6 @@ jobs:
sleep 1
done
- name: Restore DB backup
run: PGPASSWORD=postgres psql -h localhost -p 5443 -U postgres -d givethio < /tmp/backups/givethio-staging/db_backup.sql

- name: Use Node.js
uses: actions/setup-node@v1
with:
Expand All @@ -111,8 +92,8 @@ jobs:
- name: Run build
run: npm run build

- name: Run migrations
run: npm run db:migrate:run:test
# - name: Run migrations
# run: npm run db:migrate:run:test

- name: Run tests
run: npm run test
Expand Down Expand Up @@ -152,7 +133,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ github.token }}
registry: ghcr.io
repository: giveth/impact-graph
repository: generalmagicio/qacc-be # todo: check this to be correct, I just set that to be different from giveth/impact-graph
add_git_labels: true
# Add branch name to docker image tag @see{@link https://github.com/docker/build-push-action/tree/releases/v1#tag_with_ref}
tag_with_ref: true
Expand Down
14 changes: 0 additions & 14 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ DONATION_SAVE_BACKUP_DATABASE=
# Default value is saveBackup
DONATION_SAVE_BACKUP_ADAPTER=saveBackup

ENABLE_UPDATE_RECURRING_DONATION_STREAM=true

# Default value is 1
NUMBER_OF_UPDATE_RECURRING_DONATION_CONCURRENT_JOB=1

# Default value is 0 0 * * * that means one day at 00:00
UPDATE_RECURRING_DONATIONS_STREAM_CRONJOB=0 0 * * *

# Default value is 0.4
PROJECT_SEARCH_SIMILARITY_THRESHOLD=0.4

Expand All @@ -253,12 +245,6 @@ QfRound_PASSPORT_SCORE_CHECK_START_TIMESTAMP_IN_SECONDS=
ORTTO_API_KEY=FAKE_API_KEY
ORTTO_PERSON_API=https://api.ap3api.com/v1/person/merge


RECURRING_DONATION_VERIFICATION_EXPIRATION_HOURS=24
NUMBER_OF_VERIFY_RECURRING_DONATION_CONCURRENT_JOB=1
ENABLE_DRAFT_RECURRING_DONATION=true
DRAFT_RECURRING_DONATION_MATCH_EXPIRATION_HOURS=24

OPTIMISTIC_SEPOLIA_SCAN_API_KEY=

BASE_SCAN_API_URL=https://api.basescan.org/api
Expand Down
6 changes: 0 additions & 6 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ PROJECT_REVOKE_SERVICE_ACTIVE=true
GIVBACK_MIN_FACTOR=0.5
GIVBACK_MAX_FACTOR=0.8

ONRAMPER_SECRET=secreto
THIRD_PARTY_PROJECTS_ADMIN_USER_ID=4

PROJECT_FILTERS_THREADS_POOL_CONCURRENCY=1
Expand All @@ -144,7 +143,6 @@ CHAINVINE_ADAPTER=mock
CHAINVINE_API_ENABLE_TEST_MODE=true
# We should not try to verify donaitons after some hours, because checking old donations would make lots of requests to web3 providers
DONATION_VERIFICAITON_EXPIRATION_HOURS=24
RECURRING_DONATION_VERIFICAITON_EXPIRATION_HOURS=24

# We need it for monoswap
POLYGON_MAINNET_NODE_HTTP_URL=https://polygon-rpc.com
Expand Down Expand Up @@ -205,10 +203,6 @@ INSERT_USER_PASSPORT_SCORE_FOR_QF_ROUND_CRONJOB_TIME=0 0 * * *
# Optional
QfRound_PASSPORT_SCORE_CHECK_START_TIMESTAMP_IN_SECONDS=

ENABLE_DRAFT_RECURRING_DONATION=true
DRAFT_RECURRING_DONATION_MATCH_EXPIRATION_HOURS=24


OPTIMISTIC_SEPOLIA_SCAN_API_KEY=

SUPER_FLUID_ADAPTER=superfluid
Expand Down
3 changes: 1 addition & 2 deletions docs/adminPermissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ Below table has been generated by https://www.tablesgenerator.com/markdown_table
| Broadcast Notification | list, new, show | list, show | list, show | list, show | - |
| Project Update | list, show, addFeaturedProjectUpdate | list, show | list, show | list, show, addFeaturedProjectUpdate | - |
| Sybil | list, show, new, edit, delete, bulkDelete | list, show | list, show | list, show | list, show, new, edit, delete, bulkDelete |
| Project Fraud | list, show, new, edit, delete, bulkDelete | list, show | list, show | list, show | list, show, new, edit, delete, bulkDelete |
| Recurring donation | list, show, new, edit, delete, bulkDelete | list, show | list, show | list, show | - | |
| Project Fraud | list, show, new, edit, delete, bulkDelete | list, show | list, show | list, show | list, show, new, edit, delete, bulkDelete |
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
"test:backupDonationImport": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/backupDonationImport.test.ts",
"test:projectEntity": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/entities/project.test.ts",
"test:projectValidators": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/utils/validators/projectValidator.test.ts",
"test:onramperWebhook": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/onramper/webhookHandler.test.ts",
"test:donationTracker": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/segment/DonationTracker.test.ts",
"test:userRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/userRepository.test.ts",
"test:statusReasonRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/statusReasonRepository.test.ts",
Expand Down Expand Up @@ -153,15 +152,11 @@
"test:broadcastNotificationRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/broadcastNotificationRepository.test.ts",
"test:projectAddressRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/projectAddressRepository.test.ts",
"test:anchorContractAddressRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/anchorContractAddressRepository.test.ts",
"test:recurringDonationRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/recurringDonationRepository.test.ts",
"test:userPassportScoreRepository": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/userPassportScoreRepository.test.ts",
"test:recurringDonationService": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/recurringDonationService.test.ts",
"test:anchorContractAddressResolver": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/resolvers/anchorContractAddressResolver.test.ts",
"test:recurringDonationResolver": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/resolvers/recurringDonationResolver.test.ts",
"test:donationService": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/repositories/qfRoundHistoryRepository.test.ts ./src/services/donationService.test.ts",
"test:draftDonationService": "NODE_ENV=test mocha -t 99999 ./test/pre-test-scripts.ts src/services/chains/evm/draftDonationService.test.ts src/repositories/draftDonationRepository.test.ts src/workers/draftDonationMatchWorker.test.ts src/resolvers/draftDonationResolver.test.ts",
"test:draftDonationWorker": "NODE_ENV=test mocha -t 99999 ./test/pre-test-scripts.ts src/workers/draftDonationMatchWorker.test.ts",
"test:draftRecurringDonationService": "NODE_ENV=test mocha -t 99999 ./test/pre-test-scripts.ts src/services/chains/evm/draftRecurringDonationService.test.ts",
"test:userService": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/userService.test.ts",
"test:lostDonations": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/importLostDonationsJob.test.ts",
"test:reactionsService": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/reactionsService.test.ts",
Expand Down
11 changes: 1 addition & 10 deletions src/adapters/notifications/MockNotificationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Donation } from '../../entities/donation';
import { Project } from '../../entities/project';
import { User } from '../../entities/user';
import { logger } from '../../utils/logger';
import { RecurringDonation } from '../../entities/recurringDonation';

export class MockNotificationAdapter implements NotificationAdapterInterface {
async subscribeOnboarding(params: { email: string }): Promise<void> {
Expand Down Expand Up @@ -40,17 +39,9 @@ export class MockNotificationAdapter implements NotificationAdapterInterface {
}

donationReceived(params: {
donation: Donation | RecurringDonation;
donation: Donation;
project: Project;
}): Promise<void> {
if (params.donation instanceof RecurringDonation) {
logger.debug('MockNotificationAdapter donationReceived', {
projectSlug: params.project.slug,
donationTxHash: params.donation.txHash,
donationNetworkId: params.donation.networkId,
});
return Promise.resolve(undefined);
}
logger.debug('MockNotificationAdapter donationReceived', {
projectSlug: params.project.slug,
donationTxHash: params.donation.transactionId,
Expand Down
3 changes: 1 addition & 2 deletions src/adapters/notifications/NotificationAdapterInterface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Donation } from '../../entities/donation';
import { Project } from '../../entities/project';
import { UserStreamBalanceWarning, User } from '../../entities/user';
import { RecurringDonation } from '../../entities/recurringDonation';

export interface BroadCastNotificationInputParams {
broadCastNotificationId: number;
Expand Down Expand Up @@ -41,7 +40,7 @@ export interface NotificationAdapterInterface {
updateOrttoPeople(params: OrttoPerson[]): Promise<void>;

donationReceived(params: {
donation: Donation | RecurringDonation;
donation: Donation;
project: Project;
user: User | null;
}): Promise<void>;
Expand Down
93 changes: 20 additions & 73 deletions src/adapters/notifications/NotificationCenterAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import {
} from '../../repositories/userRepository';
import { buildProjectLink } from './NotificationCenterUtils';
import { buildTxLink } from '../../utils/networks';
import { RecurringDonation } from '../../entities/recurringDonation';
import { getTokenPrice } from '../../services/priceService';
import { Token } from '../../entities/token';
import { toFixNumber } from '../../services/donationService';
import { findOrganizationById } from '../../repositories/organizationRepository';

const notificationCenterUsername = process.env.NOTIFICATION_CENTER_USERNAME;
Expand Down Expand Up @@ -123,7 +119,6 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
metadata: {
...payload,
networkName,
recurringDonationTab: `${process.env.WEBSITE_URL}/account?tab=recurring-donations`,
},
segment: {
payload,
Expand Down Expand Up @@ -213,44 +208,21 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
}

async donationReceived(params: {
donation: Donation | RecurringDonation;
donation: Donation;
project: Project;
user: User | null;
}): Promise<void> {
const { project, donation, user } = params;
const isRecurringDonation = donation instanceof RecurringDonation;
let transactionId: string, transactionNetworkId: number;
if (isRecurringDonation) {
transactionId = donation.txHash;
transactionNetworkId = donation.networkId;
const token = await Token.findOneBy({
symbol: donation.currency,
networkId: transactionNetworkId,
});
const amount =
(Number(donation.flowRate) / 10 ** (token?.decimals || 18)) * 2628000; // convert flowRate in wei from per second to per month
const price = await getTokenPrice(transactionNetworkId, token!);
const donationValueUsd = toFixNumber(amount * price, 4);
logger.debug('donationReceived (recurring) has been called', {
params,
amount,
price,
donationValueUsd,
token,
});
if (donationValueUsd <= 5) return;
} else {
transactionId = donation.transactionId;
transactionNetworkId = donation.transactionNetworkId;
const donationValueUsd = donation.valueUsd;
logger.debug('donationReceived has been called', {
params,
transactionId,
transactionNetworkId,
donationValueUsd,
});
if (donationValueUsd <= 1) return;
}
const transactionId = donation.transactionId;
const transactionNetworkId = donation.transactionNetworkId;
const donationValueUsd = donation.valueUsd;
logger.debug('donationReceived has been called', {
params,
transactionId,
transactionNetworkId,
donationValueUsd,
});
if (donationValueUsd <= 1) return;

await sendProjectRelatedNotificationsQueue.add({
project,
Expand All @@ -268,12 +240,7 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
}),
},
trackId:
'donation-received-' +
transactionNetworkId +
'-' +
transactionId +
'-' +
isRecurringDonation,
'donation-received-' + transactionNetworkId + '-' + transactionId,
});
}

Expand Down Expand Up @@ -957,35 +924,16 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
const getEmailDataDonationAttributes = async (params: {
user: User;
project: Project;
donation: Donation | RecurringDonation;
donation: Donation;
}) => {
const { user, project, donation } = params;
const isRecurringDonation = donation instanceof RecurringDonation;
let amount: number,
transactionId: string,
transactionNetworkId: number,
toWalletAddress: string | undefined,
donationValueUsd: number | undefined,
donationValueEth: number | undefined,
transakStatus: string | undefined;
if (isRecurringDonation) {
transactionId = donation.txHash;
transactionNetworkId = donation.networkId;
const token = await Token.findOneBy({
symbol: donation.currency,
networkId: transactionNetworkId,
});
amount =
(Number(donation.flowRate) / 10 ** (token?.decimals || 18)) * 2628000; // convert flowRate in wei from per second to per month
} else {
amount = Number(donation.amount);
transactionId = donation.transactionId;
transactionNetworkId = donation.transactionNetworkId;
toWalletAddress = donation.toWalletAddress.toLowerCase();
donationValueUsd = donation.valueUsd;
donationValueEth = donation.valueEth;
transakStatus = donation.transakStatus;
}
const amount = Number(donation.amount);
const transactionId = donation.transactionId;
const transactionNetworkId = donation.transactionNetworkId;
const toWalletAddress = donation.toWalletAddress.toLowerCase();
const donationValueUsd = donation.valueUsd;
const donationValueEth = donation.valueEth;
const transakStatus = donation.transakStatus;
return {
email: user.email,
title: project.title,
Expand All @@ -994,7 +942,6 @@ const getEmailDataDonationAttributes = async (params: {
slug: project.slug,
projectLink: `${process.env.WEBSITE_URL}/project/${project.slug}`,
amount,
isRecurringDonation,
token: donation.currency,
transactionId: transactionId.toLowerCase(),
transactionNetworkId: Number(transactionNetworkId),
Expand Down
47 changes: 0 additions & 47 deletions src/adapters/superFluid/superFluidAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,53 +96,6 @@ const getFlowsQuery = `
},
*/
export class SuperFluidAdapter implements SuperFluidAdapterInterface {
async streamPeriods(params: {
address: string;
chain: number;
start: number;
end: number;
priceGranularity: string;
virtualization: string;
currency: string;
recurringDonationTxHash: string;
}) {
const {
address,
chain,
start,
end,
priceGranularity,
virtualization,
currency,
recurringDonationTxHash,
} = params;
try {
const response = await axios.get(
'https://accounting.superfluid.dev/v1/stream-periods',
{
params: {
addresses: address,
chains: chain,
start,
end,
priceGranularity,
virtualization,
currency,
},
},
);
// Fetch the stream table with the recurringDonation TxHash
const filteredData = response.data.filter(streamTable =>
streamTable.startedAtEvent
.toLowerCase()
.includes(recurringDonationTxHash.toLowerCase()),
);
return filteredData[0];
} catch (e) {
logger.error('superFluidAdaptor.streamPeriods error', e);
}
}

/* RESPONSE
{
"data": {
Expand Down
10 changes: 0 additions & 10 deletions src/adapters/superFluid/superFluidAdapterInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ export interface FlowUpdatedEvent {
}

export interface SuperFluidAdapterInterface {
streamPeriods(params: {
address: string;
chain: number;
start: number;
end: number;
priceGranularity: string;
virtualization: string;
currency: string;
recurringDonationTxHash: string;
}): Promise<any>;
accountBalance(accountId: string): Promise<any>;
getFlowByTxHash(params: {
receiver: string;
Expand Down
Loading

0 comments on commit d57dfee

Please sign in to comment.