|
@@ -27,6 +27,72 @@ export const actions = {
|
|
|
let networkConfig = await getNetwork()
|
|
|
alert('networkConfig next')
|
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ state.scatter.getIdentity({
|
|
|
+ accounts: [networkConfig]
|
|
|
+ }).then(async (identity) => {
|
|
|
+ let accounts = identity.accounts.find(x => x.blockchain === 'eos')
|
|
|
+
|
|
|
+ let lastAccounts = localStorage.getItem('accounts')
|
|
|
+
|
|
|
+ if (lastAccounts && JSON.parse(lastAccounts).name !== accounts.name) {
|
|
|
+ await actions.doScatterLogout(...arguments)
|
|
|
+ h5Router.push({ path: '/login' })
|
|
|
+ commit('setUserInfo', null)
|
|
|
+ commit('initChatData')
|
|
|
+ commit('initGroupData')
|
|
|
+ commit('chatAppLogin', false)
|
|
|
+ commit('toApp', false)
|
|
|
+ }
|
|
|
+
|
|
|
+ commit('setAccount', accounts)
|
|
|
+ localStorage.setItem('accounts', JSON.stringify(accounts))
|
|
|
+
|
|
|
+ // 如果当前登录的用户名和cookie中保存的account不一致
|
|
|
+ // 则删除cookie中保存的account
|
|
|
+ // 避免某些用户在移动端钱包中切换账号时跳过注销流程导致账号不一致的问题
|
|
|
+ // if (Cookie.getCookie('account') !== accounts.name) {
|
|
|
+ // Cookie.delCookie('account')
|
|
|
+ // }
|
|
|
+ // 设置全局EOS对象
|
|
|
+ window.EOS = state.scatter.eos(networkConfig, Eos, {})
|
|
|
+
|
|
|
+ // 调用scatter登录成功后获取用户EOS、GT
|
|
|
+ // dispatch('getUserEOS')
|
|
|
+ // dispatch('getUserGT')
|
|
|
+ await dispatch('getAccount')
|
|
|
+
|
|
|
+ // 每分钟刷新一次
|
|
|
+ // this.limitTimer = setInterval(() => {
|
|
|
+ // dispatch('getAccount')
|
|
|
+ // }, 60000)
|
|
|
+
|
|
|
+ resolve(true)
|
|
|
+ }).catch(e => {
|
|
|
+ reject(e)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 调起授权登录
|
|
|
+ * @param {Object} store
|
|
|
+ * @param {Object} params
|
|
|
+ */
|
|
|
+ async doScatterLoginCopy ({ dispatch, commit, state }, h5Router) {
|
|
|
+ if (!state.scatter) {
|
|
|
+ showError('Please install the scatter', 'Scatter')
|
|
|
+ } else {
|
|
|
+ if (getUserOpt('isChangeIndentity') == 1) {
|
|
|
+ await actions.doScatterLogout(...arguments)
|
|
|
+ localStorage.setItem('accounts', '')
|
|
|
+ setUserOpt('isChangeIndentity', 0)
|
|
|
+ }
|
|
|
+ alert('networkConfig before')
|
|
|
+ // 获取最快主网
|
|
|
+ let networkConfig = await getNetwork()
|
|
|
+ alert('networkConfig next')
|
|
|
+
|
|
|
// 调用getIdentity方法获取用户名
|
|
|
try {
|
|
|
var identity = await state.scatter.getIdentity({
|