Skip to content

Commit

Permalink
Merge branch 'develop' into feature/trigger-cache-invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
mradkov authored Apr 16, 2020
2 parents 0c4d4a0 + 1f4c088 commit 25a2cfa
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 49 deletions.
10 changes: 10 additions & 0 deletions src/lib/background-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getState } from '../store/plugins/persistState';
let sdk;
let controller;
let tippingContract;
let tippingContractAddress;

export const setController = contr => {
controller = contr;
Expand Down Expand Up @@ -85,6 +86,15 @@ export const getTippingContractInstance = async tx => {
return tippingContract;
};

export const getTippingContractAddress = async address => {
if (tippingContractAddress) return tippingContractAddress;
await getSDK();
tippingContractAddress = address.includes('.chain')
? getAddressByNameEntry(await sdk.api.getNameEntryByName(address), 'contract_pubkey')
: address;
return tippingContractAddress;
};

export const contractCallStatic = async ({ tx, callType }) =>
new Promise(async (resolve, reject) => {
try {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/rpcWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getTippedAmount,
resetTippedAmount,
getContractCallInfo,
getAddressByNameEntry,
} from '../popup/utils/helper';
import {
DEFAULT_NETWORK,
Expand Down Expand Up @@ -64,6 +65,7 @@ const rpcWallet = {
this.network = network;
this.compiler = this.nodes[network].compilerUrl;
this.internalUrl = this.nodes[network].internalUrl;
this.tipContractAddress = this.nodes[network].tipContract;
},
async initNodes() {
const nodes = await getActiveNetwork();
Expand Down Expand Up @@ -134,6 +136,12 @@ const rpcWallet = {
this.sdk.selectAccount(this.accountKeyPairs[0].publicKey);
this.activeAccount = this.accountKeyPairs[0].publicKey;
}
this.tipContractAddress = this.tipContractAddress.includes('.chain')
? getAddressByNameEntry(
await this.sdk.api.getNameEntryByName(this.tipContractAddress),
'contract_pubkey',
)
: this.tipContractAddress;
} catch (e) {
this.sdk = null;
}
Expand All @@ -150,7 +158,7 @@ const rpcWallet = {
return extractHostName(url);
},
async shouldOpenPopup(aepp, action, cb) {
const { isTip, amount } = getContractCallInfo(action.params.tx);
const { isTip, amount } = getContractCallInfo(action.params.tx, this.tipContractAddress);
const origin = this.getAeppOrigin(aepp);
if (BLACKLIST_AEPPS.includes(origin)) {
// deny action if in blacklist
Expand Down
10 changes: 8 additions & 2 deletions src/lib/tip-claim-relay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios from 'axios';
import { uniq } from 'lodash-es';
import { contractCallStatic, getActiveAccount, getAddressFromChainName } from './background-utils';
import {
contractCallStatic,
getActiveAccount,
getAddressFromChainName,
getTippingContractAddress,
} from './background-utils';
import { networks, DEFAULT_NETWORK, TIPPING_CONTRACT, TIP_SERVICE } from '../popup/utils/constants';

export default {
Expand All @@ -10,9 +15,10 @@ export default {

async abortIfZeroClaim(url) {
const tippingAddress = networks[DEFAULT_NETWORK].tipContract;
const address = await getTippingContractAddress(tippingAddress);
const tx = {
method: 'unclaimed_for_url',
address: tippingAddress,
address,
params: [url],
source: TIPPING_CONTRACT,
};
Expand Down
19 changes: 12 additions & 7 deletions src/lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ export default {
return res.error ? { error: true } : parseFromStorage(res);
},
async initContractInstances() {
store.commit(
'SET_TIPPING',
await store.getters.sdk.getContractInstance(TIPPING_CONTRACT, {
contractAddress: store.getters.network[store.getters.current.network].tipContract,
forceCodeCheck: true,
}),
);
try {
const contractAddress = await store.dispatch('getTipContractAddress');
store.commit(
'SET_TIPPING',
await store.getters.sdk.getContractInstance(TIPPING_CONTRACT, {
contractAddress,
forceCodeCheck: true,
}),
);
} catch (e) {
console.error(`Error creating tipping instance: ${e}`);
}
},
};
1 change: 1 addition & 0 deletions src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = (isProd, browser) => ({
'activeTab',
'clipboardWrite',
'notifications',
'tabs',
'webRequest',
'webRequestBlocking',
'*://*.chain/*',
Expand Down
7 changes: 0 additions & 7 deletions src/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ export default {
});
}
}
if ((await this.$store.dispatch('checkExtensionUpdate')) && !process.env.RUNNING_IN_TESTS) {
this.$store.commit('ADD_NOTIFICATION', {
title: '',
content: this.$t('pages.account.updateExtension'),
route: '',
});
}
if (!this.backedUpSeed) {
this.$store.commit('ADD_NOTIFICATION', {
title: '',
Expand Down
4 changes: 2 additions & 2 deletions src/popup/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@
"youNeedTo": "You need to",
"backup": "backup",
"yourSeedPhrase": "your seed phrase",
"updateExtension": "New verison available! Please update your extension!",
"updateAvailable": "New verison in store avaible!"
"updateExtension": "New version available! Please update your extension!",
"updateAvailable": "New version in store avaible!"
},
"claim": {
"claim": "Claim tips",
Expand Down
3 changes: 2 additions & 1 deletion src/popup/router/pages/Popups/PopupSignTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ export default {
},
this.txType,
);
const { isTip, amount } = getContractCallInfo(tx);
const contractAddress = await this.$store.dispatch('getTipContractAddress');
const { isTip, amount } = getContractCallInfo(tx, contractAddress);
if (isTip) {
await addTipAmount(amount);
}
Expand Down
5 changes: 3 additions & 2 deletions src/popup/router/pages/Retip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<script>
import { mapGetters } from 'vuex';
import { mapGetters, mapState } from 'vuex';
import BigNumber from 'bignumber.js';
import axios from 'axios';
import tipping from 'aepp-raendom/src/utils/tippingContractUtil';
Expand Down Expand Up @@ -61,6 +61,7 @@ export default {
'network',
'currentCurrency',
]),
...mapState(['tippingAddress']),
maxValue() {
const calculatedMaxValue = this.balance - this.minCallFee;
return calculatedMaxValue > 0 ? calculatedMaxValue.toString() : 0;
Expand Down Expand Up @@ -88,7 +89,7 @@ export default {
await this.$watchUntilTruly(() => this.sdk);
this.minCallFee = calculateFee(TX_TYPES.contractCall, {
...this.sdk.Ae.defaults,
contractId: this.network[this.current.network].tipContract,
contractId: this.tippingAddress,
callerId: this.account.publicKey,
}).min;
await this.$watchUntilTruly(() => this.tipping);
Expand Down
4 changes: 2 additions & 2 deletions src/popup/router/pages/TipPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default {
'currentCurrency',
'tip',
]),
...mapState(['tourRunning']),
...mapState(['tourRunning', 'tippingAddress']),
maxValue() {
const calculatedMaxValue = this.balance - this.minCallFee;
return calculatedMaxValue > 0 ? calculatedMaxValue.toString() : 0;
Expand Down Expand Up @@ -167,7 +167,7 @@ export default {
await this.$watchUntilTruly(() => this.sdk);
this.minCallFee = calculateFee(TX_TYPES.contractCall, {
...this.sdk.Ae.defaults,
contractId: this.network[this.current.network].tipContract,
contractId: this.tippingAddress,
callerId: this.account.publicKey,
}).min;
},
Expand Down
2 changes: 1 addition & 1 deletion src/popup/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const defaultNetworks = {
compilerUrl: 'https://compiler.aepps.com',
tokenRegistry: 'ct_UAzV9RcXEMsFcUCmrPN4iphbZroM7EHk3wvdidDYgZGGBo3hV',
tokenRegistryLima: 'ct_UAzV9RcXEMsFcUCmrPN4iphbZroM7EHk3wvdidDYgZGGBo3hV',
tipContract: 'ct_2AfnEfCSZCTEkxL5Yoi4Yfq6fF7YapHRaFKDJK3THMXMBspp5z',
tipContract: 'superhero.chain',
name: 'Mainnet',
},
};
Expand Down
8 changes: 4 additions & 4 deletions src/popup/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ const escapeCallParams = params =>
return p.toString();
});

export const getAddressByNameEntry = nameEntry =>
((nameEntry.pointers && nameEntry.pointers.find(({ key }) => key === 'account_pubkey')) || {}).id;
export const getAddressByNameEntry = (nameEntry, pointer = 'account_pubkey') =>
((nameEntry.pointers && nameEntry.pointers.find(({ key }) => key === pointer)) || {}).id;

const toFiatFixedValue = v => (v.e < -2 ? '0.01' : v.toFixed(2));

Expand Down Expand Up @@ -357,14 +357,14 @@ const resetTippedAmount = () => browser.storage.local.remove('tippedAmount');

const getTippedAmount = async () => (await browser.storage.local.get('tippedAmount')).tippedAmount;

const getContractCallInfo = transaction => {
const getContractCallInfo = (transaction, contractAddress = null) => {
if (!transaction) return { isTip: false, contractId: null, amount: 0 };

const { tipContract } = networks[DEFAULT_NETWORK];
const { tx } = TxBuilder.unpackTx(transaction);

return {
isTip: tx.contractId === tipContract,
isTip: tx.contractId === tipContract || tx.contractId === contractAddress,
contractId: tx.contractId,
amount: convertToAE(tx.amount),
};
Expand Down
22 changes: 9 additions & 13 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
aettosToAe,
getAddressByNameEntry,
} from '../popup/utils/helper';
import { BACKEND_URL, DEFAULT_NETWORK } from '../popup/utils/constants';
import { postMessage, postMessageToContent } from '../popup/utils/connection';

export default {
Expand Down Expand Up @@ -170,18 +169,6 @@ export default {
async setPendingTx({ commit, state: { transactions } }, tx) {
commit('SET_PENDING_TXS', [...transactions.pending, tx]);
},
async checkExtensionUpdate({ state: { network } }) {
const { tipContract } = network[DEFAULT_NETWORK];
let update = false;
try {
const { contractAddress } = await (await fetch(`${BACKEND_URL}/static/contract`)).json();
if (tipContract !== contractAddress) update = true;
} catch (e) {
update = false;
}

return update;
},
async setCurrency({
commit,
state: {
Expand Down Expand Up @@ -234,4 +221,13 @@ export default {

return { addresses: uniq(addresses).filter(a => a), tab };
},

async getTipContractAddress({ state: { network, current, sdk }, commit }) {
const { tipContract } = network[current.network];
const contractAddress = tipContract.includes('.chain')
? getAddressByNameEntry(await sdk.api.getNameEntryByName(tipContract), 'contract_pubkey')
: tipContract;
commit('SET_TIPPING_ADDRESS', contractAddress);
return contractAddress;
},
};
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default new Vuex.Store({
txAdvancedMode: false,
tipping: null,
tippingReceiver: {},
tippingAddress: null,
mainLoading: true,
nodeStatus: 'connecting',
currencies: {},
Expand Down
1 change: 1 addition & 0 deletions src/store/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export const UPDATE_CONNECTED_AEPP = 'UPDATE_CONNECTED_AEPP';
export const SET_MNEMONIC = 'SET_MNEMONIC';
export const SET_TOUR_RUNNING = 'SET_TOUR_RUNNING';
export const SET_TOUR_STATUS_BAR = 'SET_TOUR_STATUS_BAR';
export const SET_TIPPING_ADDRESS = 'SET_TIPPING_ADDRESS';
3 changes: 3 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ export default {
[types.SET_TOUR_STATUS_BAR](state, payload) {
state.tourStartBar = payload;
},
[types.SET_TIPPING_ADDRESS](state, payload) {
state.tippingAddress = payload;
},
};
10 changes: 3 additions & 7 deletions tests/e2e/integration/notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
describe('Tests cases for notifications page and icon', () => {
beforeEach(() => {
cy.logout().openPopup();
});
it('Have backup seed notification', () => {
cy.login()
.get('[data-cy=noti-count]')
Expand Down Expand Up @@ -31,11 +34,4 @@ describe('Tests cases for notifications page and icon', () => {
.get('[data-cy=noti-count]')
.should('be.not.visible');
});

it("Click notification icon don't open notifications page", () => {
cy.login({ backupSeed: true })
.get('[data-cy=noti]')
.click()
.urlEquals('/account');
});
});

1 comment on commit 25a2cfa

@davidyuk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.