@@ -384,6 +384,14 @@ class RNZcash: RCTEventEmitter {
384384 wallet. subscribe ( )
385385 let txs = try await wallet. synchronizer. allTransactions ( )
386386 wallet. emitTxs ( transactions: txs)
387+ let balances = try await wallet. synchronizer. getAccountsBalances ( )
388+ if let accountUUID = wallet. accountUUID,
389+ let accountBalance = balances [ accountUUID]
390+ {
391+ let data = wallet. createBalanceEventData ( from: accountBalance)
392+ wallet. emit ( " BalanceEvent " , data)
393+ }
394+
387395 resolve ( nil )
388396 case . failure:
389397 reject ( " RescanError " , " Failed to rescan wallet " , genericError)
@@ -595,6 +603,8 @@ class WalletSynchronizer: NSObject {
595603 }
596604
597605 func updateProcessorState( event: SynchronizerState ) {
606+ updateBalanceState ( event: event)
607+
598608 var scanProgress = 0
599609
600610 switch event. internalSyncStatus {
@@ -621,7 +631,6 @@ class WalletSynchronizer: NSObject {
621631 " networkBlockHeight " : self . processorState. networkBlockHeight,
622632 ]
623633 emit ( " UpdateEvent " , data)
624- updateBalanceState ( event: event)
625634 }
626635
627636 func initializeProcessorState( ) {
@@ -631,16 +640,7 @@ class WalletSynchronizer: NSObject {
631640 )
632641 }
633642
634- func updateBalanceState( event: SynchronizerState ) {
635- guard let accountUUID = self . accountUUID else {
636- return
637- }
638-
639- // Safely check if the account exists in the balances dictionary
640- guard let accountBalance = event. accountsBalances [ accountUUID] else {
641- return
642- }
643-
643+ func createBalanceEventData( from accountBalance: AccountBalance ) -> NSDictionary {
644644 // Account exists, safely access the balance properties
645645 let transparentBalance = accountBalance. unshielded
646646 let shieldedBalance = accountBalance. saplingBalance
@@ -655,15 +655,28 @@ class WalletSynchronizer: NSObject {
655655 let orchardAvailableZatoshi = orchardBalance. spendableValue
656656 let orchardTotalZatoshi = orchardBalance. total ( )
657657
658- let data : NSDictionary = [
658+ return [
659659 " alias " : self . alias,
660660 " transparentAvailableZatoshi " : String ( transparentAvailableZatoshi. amount) ,
661661 " transparentTotalZatoshi " : String ( transparentTotalZatoshi. amount) ,
662662 " saplingAvailableZatoshi " : String ( saplingAvailableZatoshi. amount) ,
663663 " saplingTotalZatoshi " : String ( saplingTotalZatoshi. amount) ,
664664 " orchardAvailableZatoshi " : String ( orchardAvailableZatoshi. amount) ,
665665 " orchardTotalZatoshi " : String ( orchardTotalZatoshi. amount) ,
666- ]
666+ ] as NSDictionary
667+ }
668+
669+ func updateBalanceState( event: SynchronizerState ) {
670+ guard let accountUUID = self . accountUUID else {
671+ return
672+ }
673+
674+ // Safely check if the account exists in the balances dictionary
675+ guard let accountBalance = event. accountsBalances [ accountUUID] else {
676+ return
677+ }
678+
679+ let data = createBalanceEventData ( from: accountBalance)
667680 emit ( " BalanceEvent " , data)
668681 }
669682
0 commit comments