+
{{
data.type == 'contractCreate' ? 'New contract' : 'AENS'
@@ -28,15 +21,8 @@
class="flex-justify-between flex-align-start flex-direction-column"
>
-
{{
- $t('pages.signTransaction.contractCall')
- }}
{{ txType }}
- {{ amount }} {{ token }}
-
- ${{ convertCurrency(usdRate, amount) }}
-
-
-
{{ $t('pages.signTransaction.fee') }}
+
+
{{ $t('pages.signTransaction.fee') }}
-
-
-
-
- {{ $t('pages.signTransaction.total') }}
-
-
- {{ totalSpend }} {{ token }}
-
@@ -111,8 +79,7 @@
$t('pages.signTransaction.confirm')
}}
-
-
+
@@ -120,13 +87,6 @@
import { mapGetters } from 'vuex';
import BigNumber from 'bignumber.js';
import { MAGNITUDE, TX_TYPES, calculateFee } from '../../utils/constants';
-import {
- convertAmountToCurrency,
- checkAddress,
- chekAensName,
- aettosToAe,
- aeToAettos,
-} from '../../utils/helper';
import Button from '../components/Button';
import UserAvatar from '../components/UserAvatar';
@@ -137,7 +97,6 @@ export default {
},
data() {
return {
- port: null,
txFee: {
min: 0,
max: 0,
@@ -145,52 +104,19 @@ export default {
signDisabled: true,
alertMsg: '',
loading: false,
- loaderType: 'transparent',
- loaderContent: '',
- errorTx: {
- error: {
- code: 1,
- data: {
- request: {},
- },
- message: 'Transaction verification failed',
- },
- id: null,
- jsonrpc: '2.0',
- },
selectedFee: 0,
usdRate: 0,
- eurRate: 0,
receiver: '',
- hash: '',
txParams: {},
- sending: false,
- contractInstance: null,
- deployed: null,
- tokenRegistryInstance: null,
};
},
props: ['data'],
async created() {
- await this.init();
+ this.init();
},
computed: {
- ...mapGetters([
- 'account',
- 'activeAccountName',
- 'balance',
- 'network',
- 'current',
- 'wallet',
- 'activeAccount',
- 'sdk',
- 'tokens',
- 'tokenBalance',
- 'isLedger',
- 'tokenRegistry',
- 'tokenRegistryLima',
- ]),
+ ...mapGetters(['account', 'activeAccountName', 'balance', 'sdk', 'tokenBalance']),
maxValue() {
const calculatedMaxValue = this.balance - this.fee;
return calculatedMaxValue > 0 ? calculatedMaxValue.toString() : 0;
@@ -204,71 +130,14 @@ export default {
maxFee() {
return this.txFee.max.toFixed(7);
},
- totalSpend() {
- if (typeof this.data.tx.token !== 'undefined') {
- return parseFloat(this.amount).toFixed(7);
- }
- return (parseFloat(this.amount) + parseFloat(this.selectedFee)).toFixed(7);
- },
insufficientBalance() {
- if (this.data.type === 'contractCall' && this.data.tx.method === 'transfer_allowance') {
- return false;
- }
- if (typeof this.data.tx.token !== 'undefined') {
- return this.tokenBalance - this.amount <= 0;
- }
-
return this.maxValue - this.amount <= 0;
- // }
- },
- inccorectAddress() {
- if (this.data.type !== 'txSign') {
- return this.receiver == null || this.receiver === '';
- }
- return !checkAddress(this.receiver) && !chekAensName(this.receiver);
},
watchBalance() {
return this.balance;
},
txType() {
- if (this.data.type === 'txSign') {
- return 'Send AE';
- }
- if (this.data.type === 'contractCall') {
- if (this.data.tx.method !== '') {
- return this.data.tx.method;
- }
- return 'Contract Call';
- }
- if (this.data.type === 'contractCreate') {
- return 'Contract Create';
- }
- if (this.data.type === 'namePreClaim') {
- return 'Name Preclaim';
- }
- if (this.data.type === 'nameClaim') {
- return 'Name Claim';
- }
- if (this.data.type === 'nameUpdate') {
- return 'Name Update';
- }
- if (this.data.type === 'nameBid') {
- return 'Name Claim';
- }
-
- return this.data.type;
- },
- isAddressShow() {
- if (
- this.data.type === 'contractCreate' ||
- this.data.type === 'namePreClaim' ||
- this.data.type === 'nameClaim' ||
- this.data.type === 'nameBid' ||
- this.data.type === 'nameUpdate'
- ) {
- return false;
- }
- return true;
+ return this.$t('transaction.type')[this.data.tx.type];
},
isNameTx() {
return (
@@ -281,9 +150,6 @@ export default {
convertSelectedFee() {
return BigNumber(this.selectedFee).shiftedBy(MAGNITUDE);
},
- token() {
- return typeof this.data.tx.token !== 'undefined' ? this.data.tx.token : 'AE';
- },
},
watch: {
watchBalance() {
@@ -291,200 +157,58 @@ export default {
},
},
methods: {
- async setContractInstance(source, contractAddress = null, options = {}) {
- try {
- let backend = 'fate';
- if (typeof this.data.tx.abi_version !== 'undefined' && this.data.tx.abi_version !== 3) {
- backend = 'aevm';
- }
- try {
- this.contractInstance = await this.$helpers.getContractInstance(source, {
- contractAddress,
- });
- this.contractInstance.setOptions({ backend });
- if (typeof options.waitMined !== 'undefined') {
- this.contractInstance.setOptions({ waitMined: options.waitMined });
- }
- } catch (e) {
- console.error(`setContractInstance: ${e}`);
- }
- return Promise.resolve(true);
- } catch (err) {
- if (this.data.popup) {
- this.errorTx.error.message = err;
- this.sending = true;
- this.port.postMessage(this.errorTx);
- setTimeout(() => {
- window.close();
- }, 1000);
- }
- }
- return Promise.resolve(false);
- },
async init() {
- this.setReceiver();
- if (this.isLedger && this.data.type !== 'txSign') {
- this.$store
- .dispatch('modals/open', {
- name: 'default',
- msg: 'Ledger currently cannot sign this type of transaction! ',
- })
- .then(() => {
- if (this.data.popup) {
- setTimeout(() => {
- window.close();
- });
- } else {
- this.redirectInExtensionAfterAction();
- }
- });
- }
if (this.data.tx.options && this.data.tx.options.amount) {
this.data.tx.amount = this.data.tx.options.amount;
- if (this.data.type === 'contractCall') {
- this.data.tx.amount = aettosToAe(this.data.tx.options.amount);
- this.data.tx.options.amount = aettosToAe(this.data.tx.options.amount);
- }
- }
- if (this.data.type === 'txSign' && this.data.popup) {
- this.data.tx.amount = aettosToAe(this.data.tx.amount);
}
- if (this.data.popup) {
- this.port = browser.runtime.connect({ name: this.data.id });
- }
- if (typeof this.data.callType !== 'undefined' && this.data.callType === 'static') {
- this.loaderType = '';
- this.loading = true;
- this.loaderContent = this.$t('pages.signTransaction.contractCalling');
-
- await this.$watchUntilTruly(() => this.sdk);
- await this.setContractInstance(this.data.tx.source, this.data.tx.address);
- try {
- const call = await this.$helpers.contractCall({
- instance: this.contractInstance,
- method: this.data.tx.method,
- params: [...this.data.tx.params, this.data.tx.options],
- });
- this.sending = true;
- this.port.postMessage(call);
- } catch (e) {
- this.errorTx.error.message = e;
- this.sending = true;
- this.port.postMessage(this.errorTx);
- }
- setTimeout(() => {
- window.close();
- }, 1000);
- } else {
- await this.$watchUntilTruly(() => this.sdk);
+ await this.$watchUntilTruly(() => this.sdk);
+ this.txParams = {
+ ...this.sdk.Ae.defaults,
+ };
+ if (this.data.type === 'namePreClaim') {
this.txParams = {
- ...this.sdk.Ae.defaults,
+ ...this.txParams,
+ accountId: this.account.publicKey,
+ commitmentId: 'cm_PtSWNMMNJ187NzGgivLFpYKptevuFQx1rKdqsDFAKVkXtyjPJ',
};
-
- if (this.data.type === 'contractCreate') {
- this.data.tx.contract = {};
- this.data.tx.contract.bytecode = (
- await this.sdk.contractCompile(this.data.tx.source)
- ).bytecode;
- this.txParams = {
- ...this.txParams,
- ownerId: this.account.publicKey,
- code: this.data.tx.contract.bytecode,
- };
- // here new contract na mqstoto na fugible token contract
- await this.setContractInstance(this.data.tx.source);
- } else if (this.data.type === 'contractCall') {
- this.data.tx.call = {};
- this.txParams = {
- ...this.txParams,
- contractId: this.data.tx.address,
- callerId: this.account.publicKey,
- };
- await this.setContractInstance(
- this.data.tx.source,
- this.data.tx.address,
- this.data.tx.options,
- );
- } else if (this.data.type === 'txSign') {
- let recipientId;
- if (this.data.tx.recipientId.substring(0, 3) === 'ak_') {
- recipientId = this.data.tx.recipientId; // eslint-disable-line prefer-destructuring
- } else {
- try {
- const address = await this.sdk.api.getNameEntryByName(this.data.tx.recipientId);
- if (typeof address.pointers[0] !== 'undefined') {
- recipientId = address.pointers[0].id;
- this.receiver = recipientId;
- } else {
- this.receiver = '';
- this.showAlert();
- return;
- }
- } catch (err) {
- this.receiver = '';
- this.showAlert();
- return;
- }
- }
- this.txParams = {
- ...this.txParams,
- senderId: this.account.publicKey,
- recipientId,
- };
- } else if (this.data.type === 'namePreClaim') {
- this.txParams = {
- ...this.txParams,
- accountId: this.account.publicKey,
- commitmentId: 'cm_PtSWNMMNJ187NzGgivLFpYKptevuFQx1rKdqsDFAKVkXtyjPJ',
- };
- } else if (this.data.type === 'nameClaim') {
- this.txParams = {
- ...this.txParams,
- accountId: this.account.publicKey,
- name: 'nm_2Wb2xdC9WMSnExyHd8aoDu2Ee8qHD94nvsFQsyiy1iEyUGPQp9',
- nameSalt: this.data.tx.preclaim.salt,
- };
- } else if (this.data.type === 'nameBid') {
- this.txParams = {
- ...this.txParams,
- accountId: this.account.publicKey,
- name: 'nm_2Wb2xdC9WMSnExyHd8aoDu2Ee8qHD94nvsFQsyiy1iEyUGPQp9',
- nameSalt: 0,
- };
- } else if (this.data.type === 'nameUpdate') {
- this.txParams = {
- ...this.txParams,
- accountId: this.account.publicKey,
- nameId: this.data.tx.claim.id,
- pointers: this.data.tx.claim.pointers,
- };
- }
- const fee = calculateFee(TX_TYPES[this.data.type], this.txParams);
- this.txFee = fee;
- this.selectedFee = this.fee.toFixed(7);
- if (this.alertMsg === '') {
- this.signDisabled = false;
- }
+ } else if (this.data.type === 'nameClaim') {
+ this.txParams = {
+ ...this.txParams,
+ accountId: this.account.publicKey,
+ name: 'nm_2Wb2xdC9WMSnExyHd8aoDu2Ee8qHD94nvsFQsyiy1iEyUGPQp9',
+ nameSalt: this.data.tx.preclaim.salt,
+ };
+ } else if (this.data.type === 'nameBid') {
+ this.txParams = {
+ ...this.txParams,
+ accountId: this.account.publicKey,
+ name: 'nm_2Wb2xdC9WMSnExyHd8aoDu2Ee8qHD94nvsFQsyiy1iEyUGPQp9',
+ nameSalt: 0,
+ };
+ } else if (this.data.type === 'nameUpdate') {
+ this.txParams = {
+ ...this.txParams,
+ accountId: this.account.publicKey,
+ nameId: this.data.tx.claim.id,
+ pointers: this.data.tx.claim.pointers,
+ };
+ }
+ const fee = calculateFee(TX_TYPES[this.data.type], this.txParams);
+ this.txFee = fee;
+ this.selectedFee = this.fee.toFixed(7);
+ if (this.alertMsg === '') {
+ this.signDisabled = false;
}
setTimeout(() => {
this.showAlert();
}, 3500);
},
- setReceiver() {
- if (this.data.type === 'txSign') {
- this.receiver = this.data.tx.recipientId;
- } else if (this.data.type === 'contractCall') {
- this.receiver = this.data.tx.address;
- }
- },
showAlert(balance = false) {
if (this.insufficientBalance && this.sdk !== null && !this.loading && balance) {
this.alertMsg = this.$t('pages.signTransaction.insufficientBalance');
- } else if (this.inccorectAddress && this.isAddressShow) {
- this.alertMsg = this.$t('pages.signTransaction.inccorectAddress');
} else {
this.alertMsg = '';
}
@@ -494,160 +218,12 @@ export default {
}
} else {
this.signDisabled = true;
- if (balance) {
- setTimeout(() => {
- if (this.data.popup && !this.sending) {
- this.errorTx.error.message = this.alertMsg;
-
- this.port.postMessage(this.errorTx);
- setTimeout(() => {
- window.close();
- }, 1000);
- }
- }, 5000);
- }
}
},
async cancelTransaction() {
- this.redirectInExtensionAfterAction();
- },
- redirectInExtensionAfterAction() {
this.$store.commit('SET_AEPP_POPUP', false);
this.$router.push('/account');
},
- signSpendTx(amount) {
- this.sdk
- .spend(amount, this.receiver, { fee: this.convertSelectedFee })
- .then(async result => {
- if (typeof result === 'object') {
- this.loading = false;
- this.hash = result.hash;
- this.$store.commit('SET_TX_QUEUE', result.hash);
- const msg = `You have sent ${this.amount} AE`;
- this.$store.dispatch('modals/open', { name: 'default', msg }).then(async () => {
- this.$store.commit('SET_AEPP_POPUP', false);
- this.redirectInExtensionAfterAction();
- });
- }
- })
- .catch(async () => {
- this.$store.commit('SET_TX_QUEUE', 'error');
- this.$store.dispatch('modals/open', { name: 'default', type: 'transaction-failed' });
- this.loading = false;
- });
- },
- async signSpendTxLedger(amount) {
- const tx = await this.sdk.spendTx({
- senderId: this.account.publicKey,
- recipientId: this.receiver,
- amount,
- fee: this.convertSelectedFee,
- });
- const sign = await this.$store.dispatch('ledgerSignTransaction', { tx });
- this.loading = false;
- if (sign.success) {
- const msg = `You have sent ${this.amount} AE`;
- this.$store.dispatch('modals/open', { name: 'default', msg }).then(async () => {
- this.$store.commit('SET_AEPP_POPUP', false);
- this.redirectInExtensionAfterAction();
- });
- } else {
- this.$store
- .dispatch('modals/open', { name: 'default', type: 'transaction-failed' })
- .then(() => {
- this.redirectInExtensionAfterAction();
- });
- }
- },
- async contractCall() {
- let call;
- try {
- let options;
- if (this.data.tx.options) {
- options = { ...this.data.tx.options };
- }
- if (this.data.tx.options && this.data.tx.options.amount) {
- this.data.tx.options.amount = aeToAettos(this.data.tx.options.amount);
- options = { ...options, ...this.data.tx.options };
- }
-
- options = { ...options, fee: this.convertSelectedFee };
- if (!this.contractInstance) {
- await this.setContractInstance(
- this.data.tx.source,
- this.data.tx.address,
- this.data.tx.options,
- );
- }
- call = await this.$helpers.contractCall({
- instance: this.contractInstance,
- method: this.data.tx.method,
- params: [...this.data.tx.params, options],
- });
-
- this.$store.commit('SET_TX_QUEUE', call.hash);
- const decoded = await call.decode();
- call.decoded = decoded;
- if (this.data.popup) {
- const { decode, ...res } = call;
- this.sending = true;
- this.port.postMessage({ ...res });
- }
- } catch (err) {
- this.$store.commit('SET_TX_QUEUE', 'error');
- this.errorTx.error.message = typeof err.message !== 'undefined' ? err.message : err;
- this.sending = true;
- this.$store.dispatch('modals/open', { name: 'default', type: 'transaction-failed' });
- }
- this.redirectInExtensionAfterAction();
- },
- async contractDeploy() {
- let deployed;
- if (this.isLedger) {
- const { ownerId, amount, gas, code, callData, deposit } = this.txParams;
- const { tx } = await this.sdk[TX_TYPES[this.data.type]]({
- ownerId,
- amount,
- gas,
- code,
- callData,
- deposit,
- });
- await this.$store.dispatch('ledgerSignTransaction', { tx });
- } else {
- try {
- deployed = await this.contractInstance.deploy([...this.data.tx.init], {
- fee: this.convertSelectedFee,
- });
- this.$store.commit('SET_TX_QUEUE', deployed.transaction);
- } catch (err) {
- this.$store.commit('SET_TX_QUEUE', 'error');
- this.$store.dispatch('modals/open', { name: 'default', type: 'transaction-failed' });
- }
- }
-
- this.loading = false;
- if (this.data.popup) {
- setTimeout(() => {
- window.close();
- }, 1000);
- } else {
- if (deployed) {
- this.deployed = deployed.address;
- const msg = `Contract deployed at address
${deployed.address}`;
- this.$store.dispatch('modals/open', { name: 'default', msg });
- }
- if (this.data.tx.contractType !== 'fungibleToken') {
- this.redirectInExtensionAfterAction();
- }
- }
- },
- copyAddress() {
- this.$copyText(this.popup.data);
- if (this.data.type === 'contractCreate' && !this.data.tx.tokenRegistry) {
- this.redirectInExtensionAfterAction();
- }
- },
redirectToTxConfirm(tx) {
this.$store.commit('SET_AEPP_POPUP', true);
@@ -671,6 +247,7 @@ export default {
name: this.data.tx.name,
recipientId: '',
preclaim,
+ type: 'NameClaimTx',
},
type: 'nameClaim',
};
@@ -683,9 +260,10 @@ export default {
}
},
async nameClaim() {
+ const { name } = this.data.tx;
if (this.data.bid) {
try {
- await this.sdk.aensBid(this.data.tx.name, this.data.tx.BigNumberAmount);
+ await this.sdk.aensBid(name, this.data.tx.BigNumberAmount);
} catch (err) {
this.$store.commit('SET_TX_QUEUE', 'error');
this.$store.dispatch('modals/open', { name: 'default', msg: err.message });
@@ -697,6 +275,23 @@ export default {
fee: this.convertSelectedFee,
});
this.$store.commit('SET_TX_QUEUE', claim.hash);
+ this.$store.commit('SET_AEPP_POPUP', false);
+ this.$router.push('/names');
+
+ await this.sdk.poll(claim.hash);
+ const { id, pointers } = await this.sdk.getName(name);
+ const tx = {
+ popup: false,
+ tx: {
+ name,
+ claim: { id, name, pointers },
+ pointers: [this.account.publicKey],
+ },
+ type: 'nameUpdate',
+ nameUpdateType: 'updatePointer',
+ };
+ this.redirectToTxConfirm(tx);
+ return;
} catch (err) {
let msg = err.message;
if (msg.includes('is not enough to execute')) {
@@ -730,33 +325,8 @@ export default {
async signTransaction() {
if (!this.signDisabled) {
this.loading = true;
- const amount = aeToAettos(this.amount);
try {
- if (this.data.type === 'txSign') {
- if (this.isLedger) {
- this.signSpendTxLedger(amount);
- } else {
- this.signSpendTx(amount);
- }
- } else if (this.data.type === 'contractCall') {
- if (this.data.callType === 'pay') {
- this.contractCall();
- } else {
- const call = await this.$helpers.contractCall({
- instance: this.contractInstance,
- method: this.data.tx.method,
- params: [...this.data.tx.params, { fee: this.convertSelectedFee }],
- });
- this.$store.commit('SET_TX_QUEUE', call.hash);
- const msg = `You have sent ${this.data.tx.amount} ${this.data.tx.token}`;
- this.$store.dispatch('modals/open', { name: 'default', msg }).then(() => {
- this.$store.commit('SET_AEPP_POPUP', false);
- this.$router.push('/account');
- });
- }
- } else if (this.data.type === 'contractCreate') {
- this.contractDeploy();
- } else if (this.data.type === 'namePreClaim') {
+ if (this.data.type === 'namePreClaim') {
this.namePreclaim();
} else if (this.data.type === 'nameClaim') {
this.nameClaim();
@@ -770,20 +340,6 @@ export default {
}
}
},
- convertCurrency(currency, amount) {
- return parseFloat(convertAmountToCurrency(currency, amount));
- },
- async checkSourceByteCode(source) {
- const byteCode = await this.sdk.contractCompile(source);
- return byteCode;
- },
- },
- async beforeDestroy() {
- if (this.data.popup) {
- if (!this.sending) {
- this.port.postMessage(this.errorTx);
- }
- }
},
beforeRouteUpdate(to, from, next) {
next();
From cbc23b75f2a2b8cf69f9830624ac0c0419f1af9e Mon Sep 17 00:00:00 2001
From: Denis Davidyuk
Date: Fri, 1 May 2020 00:51:13 +1000
Subject: [PATCH 4/4] 0.0.23
---
config.xml | 2 +-
package-lock.json | 2 +-
package.json | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/config.xml b/config.xml
index 5e9cb0947..e6b37c09b 100644
--- a/config.xml
+++ b/config.xml
@@ -1,5 +1,5 @@
-
+
Superhero
Superhero wallet
diff --git a/package-lock.json b/package-lock.json
index 51bec9b4d..03f56696f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "superhero-wallet",
- "version": "0.0.22",
+ "version": "0.0.23",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 393c0fc66..01c5df66e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "superhero-wallet",
- "version": "0.0.22",
+ "version": "0.0.23",
"description": "Superhero wallet",
"author": "Superhero",
"license": "MIT",