Skip to content

Commit

Permalink
Merge pull request #60 from Giveth/4582_support_stellar_donations
Browse files Browse the repository at this point in the history
Support stellar donations
  • Loading branch information
mohammadranjbarz authored Aug 28, 2024
2 parents d03c6f2 + 0d6e69c commit 7a9851a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
27 changes: 21 additions & 6 deletions src/givethIoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {GIVETH_TOKEN_DISTRO_ADDRESS} from "./subgraphService";
import TokenDistroJSON from '../abi/TokenDistroV2.json'
const Ethers = require("ethers");
const {isAddress} = require("ethers");

require('dotenv').config()

Expand Down Expand Up @@ -37,6 +38,19 @@ const gnosisProvider = new Ethers.JsonRpcProvider(xdaiNodeHttpUrl);
const tokenDistroGC = new Ethers.Contract(GIVETH_TOKEN_DISTRO_ADDRESS, TokenDistroJSON.abi, gnosisProvider);


export const isEvmAddress = (address: string): boolean => {
return isAddress(address);
};

const isStellarDonationAndUserLoggedInWithEvmAddress = (donation: GivethIoDonation): boolean => {
console.log('isStellarDonationAndUserLoggedIn', donation)
return Boolean (donation.transactionNetworkId === 1500 && donation?.user?.walletAddress && isEvmAddress(donation?.user?.walletAddress))
}

const donationGiverAddress = (donation: GivethIoDonation): string => {
return isStellarDonationAndUserLoggedInWithEvmAddress(donation) ? donation.user.walletAddress : donation.fromWalletAddress
}

/**
*
* @returns {Promise<[{amount:400, currency:"GIV",createdAt:"",
Expand Down Expand Up @@ -116,6 +130,7 @@ export const getEligibleDonations = async (
user {
name
email
walletAddress
}
fromWalletAddress
status
Expand All @@ -131,7 +146,7 @@ export const getEligibleDonations = async (
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& donation.isProjectVerified
&& donation.status === 'verified'
)
Expand All @@ -142,7 +157,7 @@ export const getEligibleDonations = async (
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& !donation.isProjectVerified
&& donation.status === 'verified'
)
Expand Down Expand Up @@ -201,7 +216,7 @@ export const getEligibleDonations = async (
usdValue: item.valueUsd,
givFactor: item.givbackFactor
}),
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down Expand Up @@ -232,7 +247,7 @@ export const getEligibleDonations = async (
projectRank: item.projectRank,
bottomRankInRound: item.powerRound,
givbacksRound: item.powerRound,
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down Expand Up @@ -313,7 +328,7 @@ export const getVerifiedPurpleListDonations = async (beginDate: string, endDate:
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& donation.isProjectVerified
&& donation.status === 'verified'
)
Expand All @@ -326,7 +341,7 @@ export const getVerifiedPurpleListDonations = async (beginDate: string, endDate:
createdAt: moment(item.createdAt).format('YYYY-MM-DD-hh:mm:ss'),
valueUsd: item.valueUsd,
givbackFactor: item.givbackFactor,
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down
5 changes: 2 additions & 3 deletions src/types/general.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import moment from "moment";

export interface FormattedDonation {
amount: string,
currency: string,
Expand Down Expand Up @@ -47,7 +45,8 @@ export interface GivethIoDonation {
source: string,
user: {
name: string,
email: string
email: string,
walletAddress: string
}

recurringDonation ?: {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ export const getNetworkNameById = (networkId: number): string => {
return 'optimism'
case 420 :
return 'optimism-goerli'
case 11155420 :
return 'optimism-sepolia'
case 100 :
return 'gnosis'
case 1500 :
return 'stellar'
case 137:
return 'polygon'
case 42220:
Expand Down

0 comments on commit 7a9851a

Please sign in to comment.