<commit_before>import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  OnInit,
} from '@angular/core';
import {
  FormGroup,
  FormControl,
  Validators,
  AbstractControl,
} from '@angular/forms';

import { Client } from '../../../../../services/api/client';
import { FormToastService } from '../../../../../common/services/form-toast.service';
import { WalletV2Service } from '../../wallet-v2.service';
@Component({
  selector: 'm-walletSettings--btc',
  templateUrl: './settings-btc.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WalletSettingsBTCComponent implements OnInit {
  showForm: boolean = false;
  init: boolean = false;
  inProgress: boolean = false;
  error: string;
  currentAddress: string = '';
  form;

  constructor(
    protected client: Client,
    protected cd: ChangeDetectorRef,
    private toasterService: FormToastService,
    protected walletService: WalletV2Service
  ) {}

  ngOnInit() {
    this.form = new FormGroup({
      addressInput: new FormControl('', {
        validators: [Validators.required, this.validateAddressFormat],
      }),
    });
    this.load();
  }

  async load() {
    try {
      // Check if already has an address
      const { address } = <any>(
        await this.client.get('api/v2/wallet/btc/address')
      );
      if (address) {
        this.currentAddress = address;
      }
    } catch (e) {
      console.error(e);
    }
    this.init = true;
    this.detectChanges();
  }

  validateAddressFormat(control: AbstractControl) {
    // This allows for some false positives because bech32 format allows for longer length
    // but will catch some negatives so is better than nothing
    if (<commit_msg>Allow members to enter empty BTC addresses to remove their current one<commit_after>import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  OnInit,
} from '@angular/core';
import {
  FormGroup,
  FormControl,
  Validators,
  AbstractControl,
} from '@angular/forms';

import { Client } from '../../../../../services/api/client';
import { FormToastService } from '../../../../../common/services/form-toast.service';
import { WalletV2Service } from '../../wallet-v2.service';
@Component({
  selector: 'm-walletSettings--btc',
  templateUrl: './settings-btc.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WalletSettingsBTCComponent implements OnInit {
  showForm: boolean = false;
  init: boolean = false;
  inProgress: boolean = false;
  error: string;
  currentAddress: string = '';
  form;

  constructor(
    protected client: Client,
    protected cd: ChangeDetectorRef,
    private toasterService: FormToastService,
    protected walletService: WalletV2Service
  ) {}

  ngOnInit() {
    this.form = new FormGroup({
      addressInput: new FormControl('', {
        validators: [this.validateAddressFormat],
      }),
    });
    this.load();
  }

  async load() {
    try {
      // Check if already has an address
      const { address } = <any>(
        await this.client.get('api/v2/wallet/btc/address')
      );
      if (address) {
        this.currentAddress = address;
      }
    } catch (e) {
      console.error(e);
    }
    this.init = true;
    this.detectChanges();
  }

  validateAddressFormat(control: AbstractControl) {
    if (control.value.length === 0) {
      return null;
    }

    // This allows for some false positives because bech32 format allows for longer length
    // but will catch some negatives so is better than nothing
    if (
{'fraction_non_alphanumeric': 0.12937853107344632, 'fraction_numerical': 0.003672316384180791, 'mean_word_length': 2.9652855543113104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833409', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1036, 'n_words': 267}