src/blockchain/pledges.js
/**
   * generate a mutation object used to create/update the `to` donation
   *
   * @param {object} transferInfo object containing information regarding the Transfer event
   */
generate a mutation object used to create/update the `to` donation
@param {object} transferInfo object containing information regarding the Transfer event
generate a mutation object used to create / update the ` to ` donation @param { object } transferInfo object containing information regarding the Transfer event
async function createToDonationMutation(transferInfo) {
    const {
      toPledgeAdmin,
      toPledge,
      toPledgeId,
      fromPledge,
      delegate,
      intendedProject,
      donations,
      amount,
      ts,
      txHash,
      initialTransfer,
      isReturn,
    } = transferInfo;
    const token = _retreiveTokenFromPledge(app, fromPledge);
    const [{ comment, giverAddress, ownerType, status, txNonce, actionTakerAddress }] = donations;
    const parentDonations = donations.map(d => d._id);
    const donationStatus = getDonationStatus(transferInfo);
    const mutation = {
      amount,
      amountRemaining: amount,
      giverAddress, 
      ownerId: toPledge.owner,
      ownerTypeId: toPledgeAdmin.typeId,
      ownerType: toPledgeAdmin.type,
      pledgeId: toPledgeId,
      commitTime: getCommitTime(toPledge.commitTime, ts),
      status: donationStatus,
      createdAt: ts,
      parentDonations,
      txHash,
      mined: true,
      token,
    };
    if (
      donations.length === 1 &&
      ownerType === AdminTypes.GIVER &&
      status === DonationStatus.WAITING &&
      txNonce 
    ) {
      mutation.comment = comment;
      mutation.actionTakerAddress = actionTakerAddress;
    }
    if (
      donations.length === 1 &&
      ownerType === AdminTypes.GIVER &&
      status === DonationStatus.COMMITTED
    ) {
      mutation.comment = comment;
    }
    if (initialTransfer) {
      mutation.homeTxHash = (await getHomeTxHash(txHash)) || 'unknown';
    }
    if (![DonationStatus.PAYING, DonationStatus.PAID].includes(mutation.status) && delegate) {
      Object.assign(mutation, {
        delegateId: delegate.id,
        delegateTypeId: delegate.typeId,
        delegateType: delegate.type,
      });
    }
    if (intendedProject) {
      Object.assign(mutation, {
        intendedProjectId: intendedProject.id,
        intendedProjectTypeId: intendedProject.typeId,
        intendedProjectType: intendedProject.type,
      });
    }
    if (
      isReturn ||
      (await isReturnTransfer(transferInfo)) ||
      isRejectedDelegation(transferInfo) ||
      (await isDonationBackToOriginalCampaign(app, {
        parentDonations,
        ownerTypeId: toPledgeAdmin.typeId,
        ownerType: toPledgeAdmin.type,
        status: donationStatus,
      }))
    ) {
      mutation.isReturn = true;
    }
    return mutation;
  }
async function createToDonationMutation ( transferInfo ) { const { toPledgeAdmin , toPledge , toPledgeId , fromPledge , delegate , intendedProject , donations , amount , ts , txHash , initialTransfer , isReturn , } = transferInfo ; const token = _retreiveTokenFromPledge ( app , fromPledge ) ; const [ { comment , giverAddress , ownerType , status , txNonce , actionTakerAddress } ] = donations ; const parentDonations = donations . map ( d => d . _id ) ; const donationStatus = getDonationStatus ( transferInfo ) ; const mutation = { amount , amountRemaining : amount , giverAddress , ownerId : toPledge . owner , ownerTypeId : toPledgeAdmin . typeId , ownerType : toPledgeAdmin . type , pledgeId : toPledgeId , commitTime : getCommitTime ( toPledge . commitTime , ts ) , status : donationStatus , createdAt : ts , parentDonations , txHash , mined : true , token , } ; if ( donations . length === 1 && ownerType === AdminTypes . GIVER && status === DonationStatus . WAITING && txNonce ) { mutation . comment = comment ; mutation . actionTakerAddress = actionTakerAddress ; } if ( donations . length === 1 && ownerType === AdminTypes . GIVER && status === DonationStatus . COMMITTED ) { mutation . comment = comment ; } if ( initialTransfer ) { mutation . homeTxHash = ( await getHomeTxHash ( txHash ) ) || 'unknown' ; } if ( ! [ DonationStatus . PAYING , DonationStatus . PAID ] . includes ( mutation . status ) && delegate ) { Object . assign ( mutation , { delegateId : delegate . id , delegateTypeId : delegate . typeId , delegateType : delegate . type , } ) ; } if ( intendedProject ) { Object . assign ( mutation , { intendedProjectId : intendedProject . id , intendedProjectTypeId : intendedProject . typeId , intendedProjectType : intendedProject . type , } ) ; } if ( isReturn || ( await isReturnTransfer ( transferInfo ) ) || isRejectedDelegation ( transferInfo ) || ( await isDonationBackToOriginalCampaign ( app , { parentDonations , ownerTypeId : toPledgeAdmin . typeId , ownerType : toPledgeAdmin . type , status : donationStatus , } ) ) ) { mutation . isReturn = true ; } return mutation ; }
generate a mutation object used to create/update the `to` donation
 @param {object} transferInfo object containing information regarding the Transfer event
generate a mutation object used to create / update the ` to ` donation @param { object } transferInfo object containing information regarding the Transfer event
// find token // all donations should have same giverAddress // Propagate comment and actionTakerAddress for donations created by direct donating // User has created the parent donation, not us // Propagate comment for donations created by delegating from COMMUNITY // always set homeTx on mutation b/c ui checks if homeTxHash exists to check for initial donations // lp keeps the delegation chain, but we want to ignore it