<template>
	<view class="maintoP">
		<navigation :showBack="false" :bgnum="true" class="aaa">
		<image src="../../../../static/tongyonh/Vector.png" mode="aspectFit" class="back" @click="back()" ></image>
		Add token
		</navigation>
		<view class="main">
			
         <view class="title">
         	Hot assets
         </view>
		<view class="main_con">
			<view class="item flex" v-for="item,index in coinInfo" :key="index">
				<view class="left flex2">
					<image :src="item.chainIconUrl" mode="aspectFit" class="img"></image>
				    <view class="textcon">
				    	<view class="text1">
				    		{{item.chainName}}
				    	</view>
						<view class="text2">
								{{item.contractAddress}}
						</view>
				    </view>
				</view> 
				
				<image src="../../../../static/tongyonh/IconGroup.png" mode="aspectFit" class="img" @click="addOther(item,index)" v-if="index!=imgindex"></image>
	            <image src="../../../../static/tongyonh/x-circle.png" mode="aspectFit" class="img opci" v-if="index==imgindex"></image>		
			</view>
		

		</view>



		</view>
	
	</view>
</template>

<script>
	import cont from "@/components/navigation/navigation.vue"
	import token from "@/utils/TokenUtil"
	export default {
		data() {
			return {
			coinType:'',	
			coinInfo:[],
			imgindex:-1,
			walletInfo:{},
			}
		},
	
		onLoad(item) {
		this.coinType=item.type
		this.walletInfo=uni.getStorageSync('walletInfo')
			this.getCoin();
		},
		methods: {
			back(){
				uni.reLaunch({
					url:'/pages/menu/wallet/index'
				})
			},
			// 添加代币到钱包
			addOther(item,index){
				this.imgindex=index
				console.log(item,444)
				// 获取eth代币余额
				this.$EthUtil.getTokenBalance(item.contractAddress,item.contractName).then((res) => {
				console.log(res)
				}).catch(err => {
					console.log(err)
				})
				
				if(this.coinType=='ETH'){
					if(uni.getStorageSync('itype')){
						var a=uni.getStorageSync('ethi')
						var b={
								name:item.chainName,
						        name2:item.chainName,
								xname:item.chainName,
								icon:item.chainIconUrl
							};
						this.walletInfo.ETH[a].coinList.push(b)
						uni.setStorageSync('walletInfo',this.walletInfo)
						console.log(111)
					}
					if(uni.getStorageSync('itype')==false){
						var a=uni.getStorageSync('ethiSe')
						var b={
								name:item.chainName,
						        name2:item.chainName,
								xname:item.chainName,
								icon:item.chainIconUrl
							};
				        this.walletInfo.ETH[a].coinList.push(b)
						uni.setStorageSync('wallet',this.walletInfo.ETH[a])
						
						console.log(this.walletInfo,111)
						uni.setStorageSync('walletInfo',this.walletInfo)
						console.log(222)
					}
					
					
				}
				
			
			
			
			},
	// 拿代币
	getCoin(){
		console.log(this.coinType,444)
		uni.request({
		    url: 'http://wallet-api.weirui0755.com/api/contract/getContractInfoList?chainName='+this.coinType, //请求接口
		    header: {
		          'content-type': 'application/x-www-form-urlencoded',  //自定义请求头信息
		        },
		 success: (res) => {
					this.coinInfo=res.data.data;
		    }
		 });
	},
		

		},

	};
</script>
<style scoped>

</style>

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