pub(crate) fn apply_receipt_funds_for_view(&self, account: &Account) -> Account {
        let mut account = account.clone();

        {
            fn apply_stake_credit(
                account: &mut Account,
                batch: StakeBatch,
                receipt: StakeBatchReceipt,
            ) {
                let staked_near = batch.balance().amount();
                let stake = receipt.stake_token_value().near_to_stake(staked_near);
                account.apply_stake_credit(stake);
            }

            if let Some(batch) = account.stake_batch {
                if let Some(receipt) = self.stake_batch_receipts.get(&batch.id()) {
                    apply_stake_credit(&mut account, batch, receipt);
                    account.stake_batch = None;
                }
            }

            if let Some(batch) = account.next_stake_batch {
                if let Some(receipt) = self.stake_batch_receipts.get(&batch.id()) {
                    apply_stake_credit(&mut account, batch, receipt);
                    account.next_stake_batch = None;
                }
            }
        }

        {
            fn apply_near_credit(
                account: &mut Account,
                batch: RedeemStakeBatch,
                receipt: domain::RedeemStakeBatchReceipt,
            ) {
                let redeemed_stake = batch.balance().amount();
                let near = receipt.stake_token_value().stake_to_near(redeemed_stake);
                account.apply_near_credit(near);
            }

            if let Some(RedeemLock::PendingWithdrawal) = self.redeem_stake_batch_lock {
                // NEAR funds cannot be claimed from a receipt that is pending withdrawal from the staking pool
                let batch_pending_withdrawal_id = self.redeem_stake_batch.as_ref().unwrap().id();

                if let Some(batch) = account.redeem_stake_batch {
                    if batch_pending_withdrawal_id != batch.id() {
                        if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                            apply_near_credit(&mut account, batch, receipt);
                            account.redeem_stake_batch = None
                        }
                    }
                }

                if let Some(batch) = account.next_redeem_stake_batch {
                    if batch_pending_withdrawal_id != batch.id() {
                        if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                            apply_near_credit(&mut account, batch, receipt);
                            account.next_redeem_stake_batch = None
                        }
                    }
                }
            } else {
                if let Some(batch) = account.redeem_stake_batch {
                    if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                        apply_near_credit(&mut account, batch, receipt);
                        account.redeem_stake_batch = None
                    }
                }

                if let Some(batch) = account.next_redeem_stake_batch {
                    if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                        apply_near_credit(&mut account, batch, receipt);
                        account.next_redeem_stake_batch = None
                    }
                }
            }
        }

        account
    }
/// the purpose of this method is to to compute the account's STAKE balance taking into consideration
/// that there may be unclaimed receipts on the account
/// - this enables the latest account info to be returned within the context of a contract 'view'
///   call - no receipts are physically claimed, i.e., contract state does not change
the purpose of this method is to to compute the account's STAKE balance taking into consideration
that there may be unclaimed receipts on the account
this enables the latest account info to be returned within the context of a contract 'view'
call - no receipts are physically claimed, i.e., contract state does not change
the purpose of this method is to to compute the account ' s STAKE balance taking into consideration that there may be unclaimed receipts on the account this enables the latest account info to be returned within the context of a contract ' view ' call - no receipts are physically claimed i . e . contract state does not change
pub(crate) fn apply_receipt_funds_for_view(&self, account: &Account) -> Account {
        let mut account = account.clone();
        {
            fn apply_stake_credit(
                account: &mut Account,
                batch: StakeBatch,
                receipt: StakeBatchReceipt,
            ) {
                let staked_near = batch.balance().amount();
                let stake = receipt.stake_token_value().near_to_stake(staked_near);
                account.apply_stake_credit(stake);
            }
            if let Some(batch) = account.stake_batch {
                if let Some(receipt) = self.stake_batch_receipts.get(&batch.id()) {
                    apply_stake_credit(&mut account, batch, receipt);
                    account.stake_batch = None;
                }
            }
            if let Some(batch) = account.next_stake_batch {
                if let Some(receipt) = self.stake_batch_receipts.get(&batch.id()) {
                    apply_stake_credit(&mut account, batch, receipt);
                    account.next_stake_batch = None;
                }
            }
        }
        {
            fn apply_near_credit(
                account: &mut Account,
                batch: RedeemStakeBatch,
                receipt: domain::RedeemStakeBatchReceipt,
            ) {
                let redeemed_stake = batch.balance().amount();
                let near = receipt.stake_token_value().stake_to_near(redeemed_stake);
                account.apply_near_credit(near);
            }
            if let Some(RedeemLock::PendingWithdrawal) = self.redeem_stake_batch_lock {
                // NEAR funds cannot be claimed from a receipt that is pending withdrawal from the staking pool
                let batch_pending_withdrawal_id = self.redeem_stake_batch.as_ref().unwrap().id();
                if let Some(batch) = account.redeem_stake_batch {
                    if batch_pending_withdrawal_id != batch.id() {
                        if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                            apply_near_credit(&mut account, batch, receipt);
                            account.redeem_stake_batch = None
                        }
                    }
                }
                if let Some(batch) = account.next_redeem_stake_batch {
                    if batch_pending_withdrawal_id != batch.id() {
                        if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                            apply_near_credit(&mut account, batch, receipt);
                            account.next_redeem_stake_batch = None
                        }
                    }
                }
            } else {
                if let Some(batch) = account.redeem_stake_batch {
                    if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                        apply_near_credit(&mut account, batch, receipt);
                        account.redeem_stake_batch = None
                    }
                }
                if let Some(batch) = account.next_redeem_stake_batch {
                    if let Some(receipt) = self.redeem_stake_batch_receipts.get(&batch.id()) {
                        apply_near_credit(&mut account, batch, receipt);
                        account.next_redeem_stake_batch = None
                    }
                }
            }
        }
        account
    }
pub ( crate ) fn apply_receipt_funds_for_view ( & self , account : & Account ) -> Account { let mut account = account . clone ( ) ; { fn apply_stake_credit ( account : & mut Account , batch : StakeBatch , receipt : StakeBatchReceipt , ) { let staked_near = batch . balance ( ) . amount ( ) ; let stake = receipt . stake_token_value ( ) . near_to_stake ( staked_near ) ; account . apply_stake_credit ( stake ) ; } if let Some ( batch ) = account . stake_batch { if let Some ( receipt ) = self . stake_batch_receipts . get ( & batch . id ( ) ) { apply_stake_credit ( & mut account , batch , receipt ) ; account . stake_batch = None ; } } if let Some ( batch ) = account . next_stake_batch { if let Some ( receipt ) = self . stake_batch_receipts . get ( & batch . id ( ) ) { apply_stake_credit ( & mut account , batch , receipt ) ; account . next_stake_batch = None ; } } } { fn apply_near_credit ( account : & mut Account , batch : RedeemStakeBatch , receipt : domain :: RedeemStakeBatchReceipt , ) { let redeemed_stake = batch . balance ( ) . amount ( ) ; let near = receipt . stake_token_value ( ) . stake_to_near ( redeemed_stake ) ; account . apply_near_credit ( near ) ; } if let Some ( RedeemLock :: PendingWithdrawal ) = self . redeem_stake_batch_lock { // NEAR funds cannot be claimed from a receipt that is pending withdrawal from the staking pool let batch_pending_withdrawal_id = self . redeem_stake_batch . as_ref ( ) . unwrap ( ) . id ( ) ; if let Some ( batch ) = account . redeem_stake_batch { if batch_pending_withdrawal_id != batch . id ( ) { if let Some ( receipt ) = self . redeem_stake_batch_receipts . get ( & batch . id ( ) ) { apply_near_credit ( & mut account , batch , receipt ) ; account . redeem_stake_batch = None } } } if let Some ( batch ) = account . next_redeem_stake_batch { if batch_pending_withdrawal_id != batch . id ( ) { if let Some ( receipt ) = self . redeem_stake_batch_receipts . get ( & batch . id ( ) ) { apply_near_credit ( & mut account , batch , receipt ) ; account . next_redeem_stake_batch = None } } } } else { if let Some ( batch ) = account . redeem_stake_batch { if let Some ( receipt ) = self . redeem_stake_batch_receipts . get ( & batch . id ( ) ) { apply_near_credit ( & mut account , batch , receipt ) ; account . redeem_stake_batch = None } } if let Some ( batch ) = account . next_redeem_stake_batch { if let Some ( receipt ) = self . redeem_stake_batch_receipts . get ( & batch . id ( ) ) { apply_near_credit ( & mut account , batch , receipt ) ; account . next_redeem_stake_batch = None } } } } account }
the purpose of this method is to to compute the account's STAKE balance taking into consideration
that there may be unclaimed receipts on the account
 this enables the latest account info to be returned within the context of a contract 'view'
call - no receipts are physically claimed, i.e., contract state does not change
the purpose of this method is to to compute the account ' s STAKE balance taking into consideration that there may be unclaimed receipts on the account this enables the latest account info to be returned within the context of a contract ' view ' call - no receipts are physically claimed i . e . contract state does not change
&self
account
&Account