<template>
	<view class="">
		<navigation :showBack="true" :bgnum="false">
			<text class="big_title">
				Enter Password
			</text>
		</navigation>
		<view class="main">
			<view class="big_title big_title2">
				Enter Password
			</view>
			<u-message-input @finish="finish2" :inactive-color="info?'#F16063':'#E0E5F2'" active-color="#5B53FF"
				:width="94" :maxlength="6" mode="box" :focus="fes" :dot-fill="true" @change="back">
			</u-message-input>

			<view class="infoText" v-if="info">
				Password discrepansies
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import cont from "@/components/navigation/navigation.vue"
	export default {
		data() {
			return {
				password: '',
				password2: '',
				msg: '',
				msgLength: 0,
				fes: false,
				info: false,
				transInfoPass: {

				}
			}
		},

		methods: {
			// 删除密码触发
			back(e) {
				if (e.length < 6) {
					this.info = false;
				}
			},
			transaction() {
				console.log(this.transInfoPass.privateKey)
				let that=this
				if (this.transInfoPass.type === 'ETH') {
					this.$EthUtil.transaction(this.transInfoPass.fromAddress,
						this.transInfoPass.toAddress, this.transInfoPass.amount.toString(), this.transInfoPass.privateKey.substring(2,this.transInfoPass.privateKey.length), this.transInfoPass.contractAddress,
						function(hash, err) {
							if (!err) {
							
								uni.showToast({
									title: this.$t('index').Transfersucceeded,
									icon: 'none',
									duration: 1500
								})
								setTimeout(() => {
									that.fingerSuccess = false;
									uni.reLaunch({
										url: '/pages/menu/wallet/index'
									})
								}, 1000)
							} else {
								console.log(err, 'cuowu')
							
								uni.showToast({
									title: this.$t('index').Transferfailedconfirm,
									icon: 'none',
									duration: 1500
								})
							}
						})
				} else if (this.transInfoPass.type === 'TRX') {
					this.$BtcUtil.sendTransaction(this.transInfoPass.fromAddress,
						this.transInfoPass.toAddress, this.transInfoPass.amount, this.transInfoPass.privateKey)
						.then((res) => {
							
							uni.showToast({
								title: this.$t('index').Transfersucceeded,
								icon: 'none',
								duration: 1500
							})
							setTimeout(() => {
								
								uni.reLaunch({
									url: '/pages/menu/wallet/index'
								})
							}, 1000)
						}).catch(err => {
							console.log(err, 'cuowu')
							
							uni.showToast({
								title: this.$t('index').Transferfailedconfirm,
								icon: 'none',
								duration: 1500
							})
						})
				}else if (this.transInfoPass.type === 'BTC') {
					
				}
			
			},
			finish2(e) {
				if (this.transInfoPass.password != e) {
					this.info = true;
					return;
				} else {
					this.info = false;
					this.transaction();
				}
			},

		},
		onLoad() {
			// 拿到转账信息
			this.transInfoPass = uni.getStorageSync('transInfoPass')
			uni.removeStorageSync('transInfoPass')
			console.log(this.transInfoPass, 2222)
		}
	};
</script>
<style scoped>

</style>

<style>
	@import './index.css';
</style>
