
import { init, getChainId } from '@/api/demoMETAMASK';
import * as interfaceSignature from '@/utils/interfaceSignature';
import store from '@/store';


export async function connectWallet(){
    console.log('---连接钱包');
    store.commit('wallet/SET_CURRENT_WALLET_ADDRESS', '')
    store.commit('wallet/SET_INTERFACE_SIGNATURE', '')
    store.commit('wallet/SET_EXPIRE_TIME', '')
    store.commit('network/SET_CHAIN_ID', '')
    const { address } = await init();
    const chainId = await getChainId();
    if (chainId && address) {
        // let signature,expireTime;
        // if (interfaceSignature.signatureHasExpired(chainId, address)) {
        //    const SignatureInfo= await interfaceSignature.setSignatureInfo(chainId, address) || {};
        //    signature = SignatureInfo.signature;
        //    expireTime = SignatureInfo.expireTime;
           
        // } else {
        //     const SignatureInfo = interfaceSignature.getSignatureInfo(chainId, address) || {};
        //     signature = SignatureInfo.signature;
        //     expireTime = SignatureInfo.expireTime;
        // }

        store.commit('wallet/SET_CURRENT_WALLET_ADDRESS', address)
        store.commit('network/SET_CHAIN_ID', chainId)
        // store.commit('wallet/SET_INTERFACE_SIGNATURE', signature)
        // store.commit('wallet/SET_EXPIRE_TIME', expireTime)
        
    }
}