<commit_before><template>
<div class="user-send">
	<div class="compact">
		<h1 class="display-4">{{ $t('userSend.title') }}</h1>
		<hr>
		<div class="box-wrapper" v-if="!isLoading">
			<div class="box">
				<div class="main-title display-7">{{ $t('userSend.boxTitle') }}</div>
				<hr>
				<form>
					<b-form-fieldset :label="$t('userSend.receiver')">
						<b-input-group>
							<b-form-input v-model="address" type="text" class="address-input" :placeholder="$t('userSend.receiverPlaceholder')" :class="{ 'form-error': formIsTouched && !validAddress }"></b-form-input>
							<b-input-group-button slot="right">
								<b-button @click.prevent="openSearch">
									<i class="fa fa-search"></i>
									{{ $t('userSend.lookup') }}
								</b-button>
							</b-input-group-button>
						</b-input-group>
					</b-form-fieldset>
					<div class="row">
						<div class="col-md-8">
							<b-form-fieldset :label="$t('userSend.amount')">
								<b-input-group>
									<b-form-input v-model="amount" class="mono amount-input" type="number" min="0" :class="{ 'form-error': formIsTouched && !validAmount }"></b-form-input>
									<b-input-group-button slot="right">
										<b-dropdown :text="selectedCurrency" variant="default" right>
											<b-dropdown-item v-for="currency in allowedCurrencies" @click="selectedCurrency = currency" :key="currency">
											<span class="currency">{{ currency }}</span>
											<i class="fa fa-check" v-if="currency === selectedCurrency"></i>
											</b-dropdown-item>
										</b-dropdown>
									</b-input-group-button>
								</b-input-group>
							</b-form-fieldset>
						</div>
						<div class="col-md-4">
							<b-form-fieldset :label="$t('userSend.maxAmount')">
								<div class="form-control disabled mono" :class="{ 'form-error': formIsTouched && maximumAmountExceeded }">
									{{ convertSatoshiToBitcoin(totalBalance) }} BTC
								</div>
							</b-form-fieldset>
						</div>
					</div>
					<div class="description-forex-rate" v-html="$t('userSend.descriptionForexRate', { forex: forexRate.rate })" v-if="selectedCurrency === 'USD'"></div>
					<b-button class="submit-button" :block="true" variant="primary" @click.prevent="submit" :disabled="formIsTouched && !validForm">{{ $t('userSend.button', { amount: btcAmount }) }}</b-button>
				</form>
			</div>

			<user-decrypt-private-key @private-key-decrypted="signDTO" :encrypted-private-key="encryptedPrivateKey"></user-decrypt-private-key>
		</div>
	</div>
</div>
</template>

<script>
import UtilService from '@/services/UtilService';
import HttpService from '@/services/HttpService';
import CryptoService from '@/services/CryptoService';
import UserDecryptPrivateKey from '@/components/auth/user/UserDecryptPrivateKey';

export default {
	name: 'user-send',
	data: function () {
		return {
			isLoading: true,
			selectedCurrency: 'BTC',
			allowedCurrencies: ['BTC', 'USD'],
			amount: 0,
			address: '',
			forexRate: {},
			encryptedPrivateKey: '',
			formIsTouched: false
		}
	},
	components: {
		UserDecryptPrivateKey
	},
	computed: {
		totalBalance: function () {
			let totalBalance = 0;
			if (this.$store.state.userBalance && this.$store.state.userBalance.totalBalance) {
				totalBalance = this.$store.state.userBalance.totalBalance;
			}
			return totalBalance;
		},
		btcAmount: function () {
			if (this.isLoading) {
				return 0;
			}
			if (this.selectedCurrency === 'USD') {
				return Math.round((this.amount / this.forexRate.rate) * UtilService.SATOSHI_PER_BITCOIN) / UtilService.SATOSHI_PER_BITCOIN;
			} else {
				return this.amount;
			}
		},
		validAmount: function () {
			if (this.amount <= 0) {
				return false;
			}
			if (this.maximumAmountExceeded) {<commit_msg>do not allow invalid btc amounts to be sent (<1satoshi)<commit_after><template>
<div class="user-send">
	<div class="compact">
		<h1 class="display-4">{{ $t('userSend.title') }}</h1>
		<hr>
		<div class="box-wrapper" v-if="!isLoading">
			<div class="box">
				<div class="main-title display-7">{{ $t('userSend.boxTitle') }}</div>
				<hr>
				<form>
					<b-form-fieldset :label="$t('userSend.receiver')">
						<b-input-group>
							<b-form-input v-model="address" type="text" class="address-input" :placeholder="$t('userSend.receiverPlaceholder')" :class="{ 'form-error': formIsTouched && !validAddress }"></b-form-input>
							<b-input-group-button slot="right">
								<b-button @click.prevent="openSearch">
									<i class="fa fa-search"></i>
									{{ $t('userSend.lookup') }}
								</b-button>
							</b-input-group-button>
						</b-input-group>
					</b-form-fieldset>
					<div class="row">
						<div class="col-md-8">
							<b-form-fieldset :label="$t('userSend.amount')">
								<b-input-group>
									<b-form-input v-model="amount" class="mono amount-input" type="number" min="0" :class="{ 'form-error': formIsTouched && !validAmount }"></b-form-input>
									<b-input-group-button slot="right">
										<b-dropdown :text="selectedCurrency" variant="default" right>
											<b-dropdown-item v-for="currency in allowedCurrencies" @click="selectedCurrency = currency" :key="currency">
											<span class="currency">{{ currency }}</span>
											<i class="fa fa-check" v-if="currency === selectedCurrency"></i>
											</b-dropdown-item>
										</b-dropdown>
									</b-input-group-button>
								</b-input-group>
							</b-form-fieldset>
						</div>
						<div class="col-md-4">
							<b-form-fieldset :label="$t('userSend.maxAmount')">
								<div class="form-control disabled mono" :class="{ 'form-error': formIsTouched && maximumAmountExceeded }">
									{{ convertSatoshiToBitcoin(totalBalance) }} BTC
								</div>
							</b-form-fieldset>
						</div>
					</div>
					<div class="description-forex-rate" v-html="$t('userSend.descriptionForexRate', { forex: forexRate.rate })" v-if="selectedCurrency === 'USD'"></div>
					<b-button class="submit-button" :block="true" variant="primary" @click.prevent="submit" :disabled="formIsTouched && !validForm">{{ $t('userSend.button', { amount: btcAmount }) }}</b-button>
				</form>
			</div>

			<user-decrypt-private-key @private-key-decrypted="signDTO" :encrypted-private-key="encryptedPrivateKey"></user-decrypt-private-key>
		</div>
	</div>
</div>
</template>

<script>
import UtilService from '@/services/UtilService';
import HttpService from '@/services/HttpService';
import CryptoService from '@/services/CryptoService';
import UserDecryptPrivateKey from '@/components/auth/user/UserDecryptPrivateKey';

export default {
	name: 'user-send',
	data: function () {
		return {
			isLoading: true,
			selectedCurrency: 'BTC',
			allowedCurrencies: ['BTC', 'USD'],
			amount: 0,
			address: '',
			forexRate: {},
			encryptedPrivateKey: '',
			formIsTouched: false
		}
	},
	components: {
		UserDecryptPrivateKey
	},
	computed: {
		totalBalance: function () {
			let totalBalance = 0;
			if (this.$store.state.userBalance && this.$store.state.userBalance.totalBalance) {
				totalBalance = this.$store.state.userBalance.totalBalance;
			}
			return totalBalance;
		},
		btcAmount: function () {
			if (this.isLoading) {
				return 0;
			}
			let value = 0;
			if (this.selectedCurrency === 'USD') {
				value = (this.amount / this.forexRate.rate);
			} else {
				value = this.amount;
			}
			return Math.round(value * UtilService.SATOSHI_PER_BITCOIN) / UtilService.SATOSHI_PER_BITCOIN;
		},
		validAmount: function () {
			if (this.amount <= 0) {
				return false;
			}
			if (this.maximumAmountExceeded) {
{'fraction_non_alphanumeric': 0.18466021989667505, 'fraction_numerical': 0.0031792290369585374, 'mean_word_length': 3.3490783410138247, 'pattern_counts': {'":': 0, '<': 132, '<?xml version=': 0, '>': 129, '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': '4995926', 'n_tokens_mistral': 3226, 'n_tokens_neox': 2551, 'n_words': 448}