import { Component , OnInit } from '@angular/core' ; import { Router } from '@angular/router' ; import { RippleService } from '../../ripple.service' ; import { GlobalVariable } from '../../global-variable' ; @ Component ( { selector : 'app-balance' , templateUrl : './balance.component.html' , styleUrls : [ './balance.component.css' ] } ) export class BalanceComponent implements OnInit { title : string = "资金状况" ; loadingtip : string ; accountinfo : any ; loadingBalance : boolean = false ; constructor ( private ripple , public gv , private router ) { } ngOnInit ( ) { console . log ( this . gv . wallet ) ; if ( ! this . gv . wallet ) { this . router . navigate ( [ '' ] ) ; return ; } this . ripple . getdata ( ) . subscribe ( result => { console . log ( result ) ; if ( result . ok ) { this . gv . data . contacts = result . data . contacts ; this . gv . data . tradepare = result . data . tradepare || { } ; } } ) ; this . loadingtip = "正在链接Ripple网络，请稍后..." ; this . loadingBalance = true ; this . ripple . accountinfo ( this . gv . wallet . address ) . subscribe ( result => { this . loadingBalance = false ; if ( result . ok ) { this . gv . walletIsActive = true ; this . accountinfo = this . gv . wallet . accountinfo = result . data ; this . getBalances ( this . gv . wallet . address ) ; } else { this . gv . walletIsActive = false ; if ( result . data . name == "TimeoutError" || result . data . name == "NotConnectedError" ) { this . title = "链接Ripple网络超时，请稍后再试！" ; } else { this . title = "该钱包未激活，请激活后使用。新创建的钱包，需要至少20XRP才能激活。" ; } console . log ( result ) ; } } ) ; } getBalances ( address ) { this . loadingtip = "正在加载钱包内资金数据..." ; this . loadingBalance = true ; this . ripple . getBalances ( address ) . subscribe ( result => { console . log ( result ) ; if ( result . ok ) { this . loadingBalance = false ; this . title = "" ; this . gv . wallet . balances = [ ] ; for ( let i = 0 ; i < result . data . length ; i ++ ) { let balance = result . data [ i ] ; if ( balance . value != 0 ) { this . gv . wallet . balances . push ( balance ) ; } } console . log ( this . gv . wallet . balances ) ; } else { this . title = result . data ; } } ) ; } }