Skip to content

Commit

Permalink
Merge pull request #1800 from Giveth/feat/stellar_integration
Browse files Browse the repository at this point in the history
fix: remove adding secondary donation logic
  • Loading branch information
Meriem-BM authored Sep 7, 2024
2 parents 394ef30 + 2268d8c commit 751308d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 125 deletions.
7 changes: 3 additions & 4 deletions src/resolvers/draftDonationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ export class DraftDonationResolver {
i18n.__(translationErrorMessagesKeys.PROJECT_NOT_FOUND),
);

const ownProject =
isQRDonation && anonymous
? false
: project.adminUserId === donorUser?.id;
const ownProject = isQRDonation
? false
: project.adminUserId === donorUser?.id;

if (ownProject) {
throw new Error(
Expand Down
121 changes: 0 additions & 121 deletions src/services/cronJobs/checkQRTransactionJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,112 +43,6 @@ const getToken = async (
.getOne();
};

const registerSecondaryDonation = async (
donation: DraftDonation,
fromWalletAddress: string,
prevTransactionId: string,
prevTransactionCreatedAt: string,
project: any,
token: any,
tokenPrice: any,
donor: any,
qfRound: any,
) => {
try {
// deteect similar transaction on stellar network with time difference of less/more than 1 minute
const response = await axios.get(
`${STELLAR_HORIZON_API}/accounts/${donation.toWalletAddress}/payments?limit=200&order=desc&join=transactions&include_failed=true`,
);

const transactions = response.data._embedded.records;
if (!transactions.length) return;

for (const transaction of transactions) {
const isSecondaryMatchingTransaction =
((transaction.asset_type === 'native' &&
transaction.type === 'payment' &&
transaction.to === donation.toWalletAddress &&
Number(transaction.amount) === donation.amount &&
transaction.source_account === fromWalletAddress) ||
(transaction.type === 'create_account' &&
transaction.account === donation.toWalletAddress &&
Number(transaction.starting_balance) === donation.amount &&
transaction.source_account === fromWalletAddress)) &&
Math.abs(
new Date(transaction.created_at).getTime() -
new Date(prevTransactionCreatedAt).getTime(),
) <= 60000 &&
transaction.transaction_hash !== prevTransactionId;

if (isSecondaryMatchingTransaction) {
if (
donation.toWalletMemo &&
transaction.type === 'payment' &&
transaction.transaction.memo !== donation.toWalletMemo
) {
logger.debug(
`Transaction memo does not match donation memo for donation ID ${donation.id}`,
);
return;
}

// Check if donation already exists
const existingDonation = await findDonationsByTransactionId(
transaction.transaction_hash?.toLowerCase(),
);
if (existingDonation) return;

const { givbackFactor, projectRank, bottomRankInRound, powerRound } =
await calculateGivbackFactor(project.id);

const returnedDonation = await createDonation({
amount: donation.amount,
project,
transactionNetworkId: donation.networkId,
fromWalletAddress: transaction.source_account,
transactionId: transaction.transaction_hash,
tokenAddress: donation.tokenAddress,
isProjectVerified: project.verified,
donorUser: donor,
isTokenEligibleForGivback: token.isGivbackEligible,
segmentNotified: false,
toWalletAddress: donation.toWalletAddress,
donationAnonymous: false,
transakId: '',
token: donation.currency,
valueUsd: donation.amount * tokenPrice,
priceUsd: tokenPrice,
status: transaction.transaction_successful ? 'verified' : 'failed',
isQRDonation: true,
toWalletMemo: donation.toWalletMemo,
qfRound,
chainType: token.chainType,
givbackFactor,
projectRank,
bottomRankInRound,
powerRound,
});

if (!returnedDonation) {
logger.debug(
`Error creating donation for draft donation ID ${donation.id}`,
);
return;
}

await syncDonationStatusWithBlockchainNetwork({
donationId: returnedDonation.id,
});
}
}
} catch (error) {
logger.debug(
`Error checking secondary transactions for donation ID ${donation.id}:`,
error,
);
}
};

// Check for transactions
export async function checkTransactions(
donation: DraftDonation,
Expand Down Expand Up @@ -303,21 +197,6 @@ export async function checkTransactions(
},
});

// Register secondary donation after 10 seconds
setTimeout(async () => {
await registerSecondaryDonation(
donation,
transaction.source_account,
transaction.transaction_hash,
transaction.created_at,
project,
token,
tokenPrice,
donor,
qfRound,
);
}, 10000);

return;
}
}
Expand Down

0 comments on commit 751308d

Please sign in to comment.