import InternalMessage from '@/messages/internal'
import * as MsgTypes from './messages/types'
+import accountAction from "@/models/account";
+import bytom from "@/models/bytom";
+
export default class Background {
constructor() {
this.setupInternalMessaging()
+ this.setupBytom()
+ }
+
+ setupBytom(){
+ const network = localStorage.bytomNet||'mainnet'
+ bytom.setupNet(network)
+
+ window.addEventListener('storage', storageEventHandler, false);
+ function storageEventHandler(evt){
+ if(evt.key === 'bytomNet'){
+ bytom.setupNet( evt.newValue )
+ }
+ }
}
setupInternalMessaging() {
- console.log('messaging')
LocalStream.watch((request, sendResponse) => {
console.log(request)
const message = InternalMessage.fromJson(request)
case MsgTypes.ADVTRANSFER:
this.advancedTransfer(sendResponse, message.payload)
break
+ case MsgTypes.SEND:
+ this.send(sendResponse, message.payload)
+ break
}
}
top: 0,
left: 0
},
- () => {
- sendResponse(true)
+ (window) => {
+ chrome.runtime.onMessage.addListener(function(request, sender) {
+ if(sender.tab.windowId === window.id){
+ switch (request.method){
+ case 'advanced-transfer':
+ sendResponse(request);
+ break
+ }
+ }
+ });
}
)
}
+
+ send(sendResponse, payload) {
+ const action = payload.action
+ const body = payload.body
+ if(action){
+ let promise
+ switch (action){
+ case 'listAllAccount':
+ promise = accountAction.list()
+ break
+ case 'currentAccount':
+ let account = JSON.parse(localStorage.currentAccount)
+ sendResponse(account)
+ break
+ case 'balance':
+ const id = body.id
+ const guid = body.guid
+ promise = accountAction.balance(guid, id)
+ break
+ }
+ if(promise){
+ promise.then(resp =>
+ {
+ sendResponse(resp)
+ })
+ }
+ }
+ }
}
new Background()
</div>
</div>
<br>
- <div style="width: 200px; margin: 0 auto;">
+ <div class="btn-inline" style="width: 200px;">
+ <div class="btn bg-gray" @click="close">{{ $t('transfer.cancel') }}</div>
<div class="btn bg-green" @click="$refs.modalPasswd.open()">{{ $t('transfer.confirm') }}</div>
</div>
</section>
import transaction from "@/models/transaction";
import getLang from "@/assets/language/sdk";
import modalPasswd from "@/components/modal-passwd";
+import { LocalStream } from 'extension-streams'
export default {
components: {
},
methods: {
close: function () {
- this.$router.go(-1)
+ LocalStream.send({method:'advanced-transfer',action:'reject'});
+ window.close();
},
send: function (passwd) {
let loader = this.$loading.show({
});
const inout = JSON.parse(this.$route.query.object)
- transaction.buildTransaction(this.account.guid, inout.input, inout.output).then(ret => {
+ transaction.buildTransaction(this.account.guid, inout.input, inout.output, inout.gas).then(ret => {
const arrayData = ret.result.data.signing_instructions[0].data
return transaction.advancedTransfer(this.account.guid, ret.result.data, passwd, arrayData)
- .then(() => {
+ .then((resp) => {
loader.hide();
+ LocalStream.send({method:'advanced-transfer',action:'success', message:resp});
this.$dialog.show({
body: this.$t("transfer.success")
});
- this.$router.push('/')
+ this.$router.push('/');
})
.catch(error => {
throw error
});
}).catch(error => {
loader.hide();
+
this.$dialog.show({
body: getLang(error.message)
});
});
}
}, mounted() {
- if (this.$route.params.account != undefined) {
- this.account = this.$route.params.account;
- }
+ const inout = JSON.parse(this.$route.query.object);
- account.setupNet(localStorage.bytomNet);
- account.list().then(accounts => {
- this.accounts = accounts;
- this.accounts.forEach(function (ele) {
- ele.label = ele.alias
- ele.value = ele.guid
- });
+ if (inout.account != undefined) {
+ this.account = inout.account;
+ }
- if (Object.keys(this.account).length == 0) {
- this.account = accounts[0]
- }
- });
- }
+ account.setupNet(localStorage.bytomNet);
+ account.list().then(accounts => {
+ this.accounts = accounts;
+ this.accounts.forEach(function (ele) {
+ ele.label = ele.alias
+ ele.value = ele.guid
+ });
+
+ if (Object.keys(this.account).length == 0) {
+ this.account = accounts[0]
+ }
+ });
+ }
};
</script>