import { ChangeDetectionStrategy , Component , Input , OnInit , OnDestroy , } from '@angular/core' ; import noOp from '../../../../../helpers/no-op' ; import { SupportTier } from '../../../../wire/v2/support-tiers.service' ; import { ChannelShopMembershipsEditService } from './edit.service' ; import { ConfigsService } from '../../../../../common/services/configs.service' ; import { Subscription } from 'rxjs' ; import { WalletV2Service } from '../../../../wallet/components/wallet-v2.service' ; @ Component ( { selector : 'm-channelShopMemberships__edit' , changeDetection : ChangeDetectionStrategy . OnPush , templateUrl : 'edit.component.html' , styleUrls : [ 'edit.component.ng.scss' ] , providers : [ ChannelShopMembershipsEditService , WalletV2Service ] , } ) export class ChannelShopMembershipsEditComponent implements OnInit , OnDestroy { public readonly tokenExchangeRate : number ; /**
     * Save intent
     */ onSave : ( any ) => any = noOp ; /**
     * Dismiss intent
     */ onDismissIntent : ( ) => void = noOp ; param onSave param onDismissIntent set opts ( { onSave , onDismissIntent } ) { this . onSave = onSave || noOp ; this . onDismissIntent = onDismissIntent || noOp ; } param supportTier @ Input ( 'supportTier' ) set data ( supportTier ) { this . load ( supportTier ) ; } canSaveSubscription : Subscription ; canSave : boolean = false ; param service constructor ( public service , private configs ) { this . tokenExchangeRate = configs . get ( 'token_exchange_rate' ) || 1.25 ; } ngOnInit ( ) { this . canSaveSubscription = this . service . canSave$ . subscribe ( canSave => ( this . canSave = canSave ) ) ; } ngOnDestroy ( ) { this . canSaveSubscription . unsubscribe ( ) ; } param supportTier load ( supportTier ) { this . service . reset ( ) ; if ( ! supportTier ) { return ; } this . service . load ( supportTier ) ; } param amount setUsd ( amount ) { amount = amount . trim ( ) ; if ( amount . slice ( - 1 ) === '.' ) { return ; } const numericAmount = parseFloat ( amount . replace ( /,/g , '' ) || '0' ) ; if ( isNaN ( numericAmount ) ) { return ; } this . service . usd$ . next ( numericAmount ) ; } /**
     * Saves a Support Tier
     */ async save ( ) { if ( ! this . canSave ) { return ; } const supportTier = await this . service . save ( ) . toPromise ( ) ; if ( supportTier ) { this . onSave ( supportTier ) ; } } }