From b144e9e5e724c9b8fdb1622c55a8c9da13d58a94 Mon Sep 17 00:00:00 2001 From: Zhiting Lin Date: Tue, 4 Aug 2020 11:03:12 +0800 Subject: [PATCH] disable the wallet connection --- src/assets/language/cn.js | 7 +++++++ src/assets/language/en.js | 7 +++++++ src/background.js | 26 ++++++++++++++++++++++++++ src/content.js | 1 + src/dapp.js | 9 +++++++++ src/messages/types.js | 1 + src/utils/errors/Error.js | 7 ++++++- src/utils/errors/ErrorTypes.js | 1 + src/views/prompts/authentication.vue | 14 ++++++++------ 9 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/assets/language/cn.js b/src/assets/language/cn.js index ff4be84..8599f0c 100644 --- a/src/assets/language/cn.js +++ b/src/assets/language/cn.js @@ -115,6 +115,13 @@ const cn = { cancel:'取消', confirm:'确认授权' }, + disable:{ + title:'取消授权', + domain: '域名', + message: '取消授权用户信息。', + cancel:'取消', + confirm:'取消授权' + }, receive:{ address: '地址', tips:'提示:点击地址进行拷贝。', diff --git a/src/assets/language/en.js b/src/assets/language/en.js index 878965b..39c2c9b 100644 --- a/src/assets/language/en.js +++ b/src/assets/language/en.js @@ -115,6 +115,13 @@ const en = { cancel:'Cancel', confirm:'Connect' }, + disable:{ + title:'Disable Request', + domain: 'Domain', + message: 'would like to diable your connection', + cancel:'Cancel', + confirm:'Disable' + }, receive:{ address: 'Address', tips:'Tips: Click address to copy directly.', diff --git a/src/background.js b/src/background.js index 1d9329e..3528910 100644 --- a/src/background.js +++ b/src/background.js @@ -57,6 +57,9 @@ export default class Background { case MsgTypes.ENABLE: Background.authenticate(sendResponse, message.payload) break + case MsgTypes.DISABLE: + Background.disauthenticate(sendResponse, message.payload) + break case MsgTypes.SET_PROMPT: Background.setPrompt(sendResponse, message.payload); break; @@ -338,6 +341,29 @@ export default class Background { }) } + static disauthenticate(sendResponse, payload){ + Background.load(bytom => { + const domain = payload.domain; + + var index = bytom.settings.domains.indexOf(domain); + if(index !== -1) { + NotificationService.open(new Prompt(PromptTypes.REQUEST_AUTH, payload.domain, {type:'dis'}, approved => { + if(approved === false || approved.hasOwnProperty('isError')) sendResponse(approved); + else { + bytom.settings.domains.splice(index, 1); + if(approved === true){ + this.update(() => sendResponse({status:'success'}), bytom); + }else{ + this.update(() => sendResponse(approved), bytom); + } + } + })); + } else{ + sendResponse(Error.disauth()); + } + }) + } + } diff --git a/src/content.js b/src/content.js index 241bda4..17edb38 100644 --- a/src/content.js +++ b/src/content.js @@ -109,6 +109,7 @@ class Content { this.transfer(msg.type, networkMessage) break case MsgTypes.ENABLE: + case MsgTypes.DISABLE: this.enable(msg.type, networkMessage) break default: diff --git a/src/dapp.js b/src/dapp.js index ca7e3d5..545e8c2 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -83,6 +83,15 @@ export default class Bytomdapp { }) } + disable(){ + return _send(MsgTypes.DISABLE) + .then(async (res) =>{ + this.default_account = ''; + this.defaultAccount = ''; + return res; + }) + } + //v1.4.0 setChain(params) { return _send(MsgTypes.SETCHAIN, params) diff --git a/src/messages/types.js b/src/messages/types.js index 3b1ee85..f21f709 100644 --- a/src/messages/types.js +++ b/src/messages/types.js @@ -5,6 +5,7 @@ export const UPDATE_BYTOM = 'updateBytom' export const AUTHENTICATE = 'authenticate' export const TRANSFER = 'transfer' export const ENABLE = 'enable' +export const DISABLE = 'disable' export const ADVTRANSFER = 'advTransfer' export const SIGNTRANSACTION = 'signTransaction' export const SIGNMESSAGE = 'signMessage' diff --git a/src/utils/errors/Error.js b/src/utils/errors/Error.js index df50896..063aee5 100644 --- a/src/utils/errors/Error.js +++ b/src/utils/errors/Error.js @@ -7,7 +7,8 @@ export const ErrorCodes = { LOCKED:423, TOO_MANY_REQUESTS:429, TYPE_MISSED:411, - TYPE_DUPLICATE:405 + TYPE_DUPLICATE:405, + TYPE_DISAUTH:401 }; export default class Error { @@ -27,6 +28,10 @@ export default class Error { return new Error(ErrorTypes.TYPE_DUPLICATED, `The current value has been set to '${_type}', please select another parameter.`, ErrorCodes.TYPE_DUPLICATE) } + static disauth(){ + return new Error(ErrorTypes.TYPE_DISAUTH, `The current domain is no auth, it can't be disauth`, ErrorCodes.TYPE_DISAUTH) + } + static promptClosedWithoutAction(){ return new Error(ErrorTypes.PROMPT_CLOSED, "The user closed the prompt without any action.", ErrorCodes.TIMED_OUT) } diff --git a/src/utils/errors/ErrorTypes.js b/src/utils/errors/ErrorTypes.js index 7b794cb..84b63e4 100644 --- a/src/utils/errors/ErrorTypes.js +++ b/src/utils/errors/ErrorTypes.js @@ -3,3 +3,4 @@ export const LOCKED = 'locked'; export const PROMPT_CLOSED = 'prompt_closed'; export const TYPE_MISSED = 'type_missed'; export const TYPE_DUPLICATED = 'type_duplicated'; +export const TYPE_DISAUTH = 'type_disauth'; diff --git a/src/views/prompts/authentication.vue b/src/views/prompts/authentication.vue index cd58c1c..3018e86 100644 --- a/src/views/prompts/authentication.vue +++ b/src/views/prompts/authentication.vue @@ -65,14 +65,14 @@
-

{{$t('enable.title')}}

+

{{ isDisAuth? $t('disable.title'): $t('enable.title')}}

- + @@ -80,12 +80,12 @@
-
{{$t('enable.message')}}
+
{{ isDisAuth? $t('disable.message'): $t('enable.message') }}
-
{{$t('enable.cancel')}}
-
{{$t('enable.confirm')}}
+
{{ isDisAuth? $t('disable.cancel'): $t('enable.cancel') }}
+
{{ isDisAuth? $t('disable.confirm'): $t('enable.confirm') }}
@@ -100,7 +100,8 @@ import NotificationService from '../../services/NotificationService' export default { data() { return { - prompt:'' + prompt:'', + isDisAuth: false }; }, computed: { @@ -118,6 +119,7 @@ export default { } }, mounted() { this.prompt = window.data || apis.extension.getBackgroundPage().notification || null; + this.isDisAuth = (this.prompt.data.type == 'dis') } }; -- 2.11.0
{{$t('enable.domain')}}{{ isDisAuth? $t('disable.domain'): $t('enable.domain') }} {{prompt.domain}}