<template>
	<view class="">
		<navigation :showBack="true" :bgnum="false">
			<text class="big_title">
				Transaction password
			</text>
		</navigation>
		<view class="main">
			<view class="big_title" v-if="borNum">
				Set transaction password
			</view>
			<view class="big_title" v-if="borNum2">
				Please enter again
			</view>
			<view class="title">
				Secure transaction passwords, <br>please do not disclose
			</view>
			<u-message-input @finish="finish" inactive-color="#E0E5F2" active-color="#5B53FF" :width="94" :maxlength="6"
				mode="box" :focus="fes" :dot-fill="true" v-if="borNum"></u-message-input>
			<u-message-input @finish="finish2" :inactive-color="info?'#F16063':'#E0E5F2'" active-color="#5B53FF"
				:width="94" :maxlength="6" mode="box" :focus="fes" :dot-fill="true" v-if="borNum2" @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,
				borNum: true,
				borNum2: false,
				info: false,
				word: {},
				walletInfo: {},
				btcBalance: 0,
				ethBbalance: 0,
				trxBbalance: 0,
			}
		},
		watch: {

		},

		methods: {
	     // 首次创建三条主链钱包 首次执行这里
			setWalletInfo(e) {
				this.word = uni.getStorageSync('word');
				this.$walletUtil.initialWallet(this.word,this.password )
			},

			// 删除密码触发
			back(e) {
				if (e.length < 6) {
					this.info = false;
				}
			},
			finish2(e) {
				if (this.password != e) {
					this.info = true;
					return;
				} else {
	
				// 私鑰創建
		var createWalletName= uni.getStorageSync('createWalletName')
		var privateKey= uni.getStorageSync('privateKey')
	uni.setStorageSync('privateKey', this.wordInfo);
	try { 
	 this.$walletUtil.privateKeyEstablishWallet(createWalletName,privateKey,this.password);
	 			uni.showToast({
	 				title: 'Set successfully',
	 				icon: 'success',
	 				duration: 1500,
	 			})
	 			setTimeout(() => {
	 				uni.navigateTo({
	 					url: '../../wallet/index'
	 				})
	 			}, 1500)
	}
	catch(err){
		console.log(err,11)
	   uni.showToast({
	   	title: 'Creation failed',
	   	icon: 'none',
	   	duration: 1500,
	   })
	   
	}
		 
				
				
					this.info = false;
				}
				
			},
			// 第一次存密码
			finish(e) {
				this.password = e
				var that = this;
				that.borNum = false;
				that.borNum2 = false;
			
				setTimeout(() => {
					that.borNum2 = true;
				}, 50)

			},
		},
		onLoad() {

		}
	};
</script>
<style scoped>

</style>

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