case MsgTypes.TRANSFER:
this.transfer(sendResponse, message.payload)
break
+ case MsgTypes.ADVTRANSFER:
+ this.advancedTransfer(sendResponse, message.payload)
+ break
}
}
}
)
}
+
+ advancedTransfer(sendResponse, payload) {
+ var promptURL = chrome.extension.getURL('pages/prompt.html')
+ var queryString = 'object='+JSON.stringify(payload)
+ console.log(promptURL, queryString)
+ chrome.windows.create(
+ {
+ url: `${promptURL}#advancedTransfer?${queryString}`,
+ type: 'popup',
+ width: 350,
+ height: 623,
+ top: 0,
+ left: 0
+ },
+ () => {
+ sendResponse(true)
+ }
+ )
+ }
}
new Background()
this.sync(msg)
break
case MsgTypes.TRANSFER:
- this.transfer(networkMessage)
+ case MsgTypes.ADVTRANSFER:
+ this.transfer(msg.type, networkMessage)
break
default:
stream.send(networkMessage.error('errtest'), EventNames.INJECT)
stream.synced = true
}
- transfer(message) {
+ transfer(type, message) {
if (!isReady) return
- InternalMessage.payload(MsgTypes.TRANSFER, message.payload)
+ InternalMessage.payload(type, message.payload)
.send()
.then(res => this.respond(message, res))
}
amount: amount
})
}
+
+ advancedTransfer(input, output) {
+ return _send(MsgTypes.ADVTRANSFER, {
+ input,
+ output
+ })
+ }
}
export const PUSH_BYTOM = 'pushBytom'
export const AUTHENTICATE = 'authenticate'
export const TRANSFER = 'transfer'
+export const ADVTRANSFER = 'advTransfer'
return retPromise;
};
+transaction.buildTransaction = function(guid, inputs, outputs) {
+ let retPromise = new Promise((resolve, reject) => {
+ bytom.transaction
+ .buildTransaction(guid, inputs, outputs)
+ .then(res => {
+ resolve(res);
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
+ return retPromise;
+};
+
transaction.transfer = function(guid, transaction, password) {
let retPromise = new Promise((resolve, reject) => {
bytom.transaction
return retPromise;
};
+transaction.advancedTransfer = function(guid, transaction, password, arrayData) {
+ let retPromise = new Promise((resolve, reject) => {
+ bytom.transaction
+ .signTransaction(guid, JSON.stringify(transaction), password)
+ .then(ret => {
+ let signatures = ret.signatures
+ signatures[0] = arrayData
+ bytom.transaction
+ .submitPayment(guid, ret.raw_transaction, signatures)
+ .then(res3 => {
+ resolve(res3);
+ })
+ .catch(error => {
+ reject(error);
+ });
+ })
+ .catch(error => {
+ reject(error);
+ });
+ });
+
+ return retPromise;
+};
+
export default transaction;
}
},
{
+ path: '/advancedTransfer',
+ name: 'advanced-transfer',
+ meta: { title: '高级转账' },
+ component: resolve => {
+ require(['@/views/advancedTransfer.vue'], resolve)
+ }
+ },
+ {
path: '/transfer/info',
name: 'transfer-info',
meta: { title: '交易详情' },
--- /dev/null
+<style lang="" scoped>
+.header {
+ height: 150px;
+}
+.balance {
+ text-align: center;
+ margin-top: 15px;
+}
+.balance .token-icon {
+ height: 38px;
+ width: 38px;
+ margin-right: 5px;
+}
+.balance .token-amount {
+ display: inline-block;
+ font-size: 45px;
+ line-height: 45px;
+}
+.balance .token-amount .asset {
+ font-size: 18px;
+ margin-left: 2px;
+}
+.form {
+ padding: 10px 22px;
+}
+.form-item-group {
+ display: flex;
+}
+.form-item-group .form-item {
+ width: 40%;
+}
+
+.btn-inline {
+ display: flex;
+ padding: 0;
+}
+.btn-inline .btn {
+ margin: 10px 15px;
+}
+</style>
+
+<template>
+ <div class="warp-chlid bg-gray">
+ <section class="header bg-green">
+ <i class="iconfont icon-back" @click="close"></i>
+ <div class="balance">
+ <img src="@/assets/logo.png" class="token-icon">
+ <div class="token-amount">
+ {{accountBalance}}
+ <span class="asset">BTM</span>
+ </div>
+ </div>
+ </section>
+
+ <section class="form">
+ <div class="form-item-group">
+ <div class="form-item">
+ <!-- <label>账户</label> -->
+ <v-select :clearable="false" v-model="account" style="height: 32px;width: 125px;" label="alias" :options="accounts"></v-select>
+ </div>
+ </div>
+ <br>
+ <div style="width: 200px; margin: 0 auto;">
+ <div class="btn bg-green" @click="$refs.modalPasswd.open()">{{ $t('transfer.confirm') }}</div>
+ </div>
+ </section>
+
+ <!-- modal -->
+ <modalPasswd ref="modalPasswd" @confirm="send"></modalPasswd>
+ </div>
+</template>
+
+<script>
+import account from "@/models/account";
+import transaction from "@/models/transaction";
+import getLang from "@/assets/language/sdk";
+import modalPasswd from "@/components/modal-passwd";
+
+export default {
+ components: {
+ modalPasswd
+ },
+ data() {
+ const ASSET_BTM =
+ "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
+ return {
+ show: false,
+ accounts: [],
+ guid: null,
+ account: {},
+ accountBalance: 0.00,
+ transaction: {
+ to: "",
+ asset: ASSET_BTM,
+ amount: "",
+ fee: "",
+ cost: ""
+ }
+ };
+ },
+ computed: {
+ unit() {
+ return this.assets[this.transaction.asset];
+ }
+ },
+ watch: {
+ account: function (newAccount) {
+ this.guid = newAccount.guid;
+ },
+ guid: function (newGuid) {
+ this.accounts.forEach(account => {
+ if (account.guid == newGuid.guid) {
+ this.account = account;
+ return;
+ }
+ });
+
+ account.balance(newGuid).then(balance => {
+ this.accountBalance = balance;
+ }).catch(error => {
+ console.log(error);
+ });
+ }
+ },
+ methods: {
+ close: function () {
+ this.$router.go(-1)
+ },
+ send: function (passwd) {
+ let loader = this.$loading.show({
+ // Optional parameters
+ container: null,
+ canCancel: true,
+ onCancel: this.onCancel
+ });
+ const inout = JSON.parse(this.$route.query.object)
+
+ transaction.buildTransaction(this.account.guid, inout.input, inout.output).then(ret => {
+ const arrayData = ret.result.data.signing_instructions[0].data
+ return transaction.advancedTransfer(this.account.guid, ret.result.data, passwd, arrayData)
+ .then(() => {
+ loader.hide();
+ this.$dialog.show({
+ body: this.$t("transfer.success")
+ });
+ 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;
+ }
+
+ 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>