Skip to content

Commit

Permalink
Merge branch 'develop' into feature/set-active-name
Browse files Browse the repository at this point in the history
  • Loading branch information
mradkov authored Apr 30, 2020
2 parents 4f0bcf2 + 5e3cb5b commit 041305b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 32 deletions.
46 changes: 33 additions & 13 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import './lib/initPolyfills';
import uid from 'uuid';
import { phishingCheckUrl, getPhishingUrls, setPhishingUrl } from './popup/utils/phishing-detect';
import { detectConnectionType } from './popup/utils/helper';
import { buildTx } from './popup/utils';
import WalletController from './wallet-controller';
import Notification from './notifications';
import { setController, switchNode } from './lib/background-utils';
import './lib/initPolyfills';
import { PopupConnections } from './lib/popup-connection';
import RedirectChainNames from './lib/redirect-chain-names';
import rpcWallet from './lib/rpcWallet';
import TipClaimRelay from './lib/tip-claim-relay';
import Notification from './notifications';
import { buildTx } from './popup/utils';
import { popupProps } from './popup/utils/config';
import {
HDWALLET_METHODS,
AEX2_METHODS,
NOTIFICATION_METHODS,
CONNECTION_TYPES,
DEFAULT_NETWORK,
HDWALLET_METHODS,
NOTIFICATION_METHODS,
} from './popup/utils/constants';
import { popupProps } from './popup/utils/config';
import TipClaimRelay from './lib/tip-claim-relay';
import RedirectChainNames from './lib/redirect-chain-names';
import { setController, switchNode } from './lib/background-utils';
import { PopupConnections } from './lib/popup-connection';
import { detectConnectionType } from './popup/utils/helper';
import { getPhishingUrls, phishingCheckUrl, setPhishingUrl } from './popup/utils/phishing-detect';
import WalletController from './wallet-controller';
import Logger from './lib/logger';

const controller = new WalletController();
Expand Down Expand Up @@ -113,6 +113,26 @@ if (process.env.IS_EXTENSION && require.main.i === module.id) {
}
}
});

const contextMenuItem = {
id: 'superheroTip',
title: 'Tip',
};

browser.contextMenus.removeAll();
browser.contextMenus.create(contextMenuItem);
browser.contextMenus.onClicked.addListener(({ menuItemId, pageUrl }) => {
if (menuItemId === 'superheroTip') {
const url = `/tip?url=${pageUrl}`;
localStorage.setItem('tipUrl', url);
browser.windows.create({
url: `popup/popup.html#${url}`,
type: 'popup',
height: 600,
width: 375,
});
}
});
}

// eslint-disable-next-line import/prefer-default-export
Expand Down
1 change: 1 addition & 0 deletions src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = (isProd, platform) => ({
'videoCapture',
'activeTab',
'clipboardWrite',
'contextMenus',
'notifications',
'tabs',
'webRequest',
Expand Down
8 changes: 8 additions & 0 deletions src/popup/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ router.beforeEach(async (to, from, next) => {
await helper.pollGetter(() => store.state.isRestored);
if (store.getters.isLoggedIn) {
if (!store.getters.sdk) wallet.initSdk();
if (localStorage.tipUrl) {
next(localStorage.tipUrl);
delete localStorage.tipUrl;
return;
}
next(to.meta.ifNotAuthOnly ? '/account' : undefined);
return;
}
Expand All @@ -62,6 +67,9 @@ router.beforeEach(async (to, from, next) => {
return;
}
wallet.initSdk();

if (localStorage.tipUrl) delete localStorage.tipUrl;

if (window.RUNNING_IN_POPUP) {
store.commit('SET_AEPP_POPUP', true);
next(
Expand Down
3 changes: 3 additions & 0 deletions src/popup/router/pages/ClaimTips.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="claim-tips popup">
<p class="primary-title text-left mb-8 f-16">
URL to claim tips for
</p>
<Input size="m-0 sm" v-model="url" :error="!normalizedUrl" />

<Button @click="claimTips" :disabled="!normalizedUrl">
Expand Down
18 changes: 10 additions & 8 deletions src/popup/router/pages/Tip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default {
editUrl: true,
IS_EXTENSION: process.env.IS_EXTENSION,
RUNNING_IN_TESTS: process.env.RUNNING_IN_TESTS,
tipFromPopup: false,
};
},
computed: {
Expand Down Expand Up @@ -139,15 +140,12 @@ export default {
async created() {
await this.persistTipDetails();
if (process.env.IS_EXTENSION) {
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
if (tab) {
this.url = tab.url;
const [{ url }] = await browser.tabs.query({ active: true, currentWindow: true });
this.tipFromPopup = url.includes(browser.runtime.getURL('popup/popup.html'));
if (url && !this.tipFromPopup) {
this.url = url;
}
}
// if mobile
if (!this.IS_EXTENSION && !this.RUNNING_IN_TESTS) {
this.url = null;
}
await this.$watchUntilTruly(() => this.sdk && this.tippingAddress);
this.minCallFee = calculateFee(TX_TYPES.contractCall, {
...this.sdk.Ae.defaults,
Expand Down Expand Up @@ -211,11 +209,15 @@ export default {
this.$router.push('/account');
}
} catch (e) {
this.$store.dispatch('modals/open', { name: 'default', type: 'transaction-failed' });
await this.$store.dispatch('modals/open', { name: 'default', type: 'transaction-failed' });
e.payload = { url: this.url };
throw e;
} finally {
this.loading = false;
if (this.tipFromPopup) {
localStorage.removeItem('lsroute');
window.close();
}
}
},
toEdit() {
Expand Down
17 changes: 6 additions & 11 deletions src/popup/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,14 @@ const getExtensionProtocol = () => {

export const detectConnectionType = port => {
const extensionProtocol = getExtensionProtocol();
const senderUrl = port.sender.url.split('?');
const [senderUrl] = port.sender.url.split('?');
let type = CONNECTION_TYPES.OTHER;
if (
port.name === CONNECTION_TYPES.EXTENSION &&
(senderUrl[0] === `${extensionProtocol}://${browser.runtime.id}/popup/popup.html` ||
detectBrowser() === 'Firefox')
) {
const isExtensionSender =
senderUrl.includes(`${extensionProtocol}://${browser.runtime.id}/popup/popup.html`) ||
detectBrowser() === 'Firefox';
if (port.name === CONNECTION_TYPES.EXTENSION && isExtensionSender) {
type = CONNECTION_TYPES.EXTENSION;
} else if (
port.name === CONNECTION_TYPES.POPUP &&
(senderUrl[0] === `${extensionProtocol}://${browser.runtime.id}/popup/popup.html` ||
detectBrowser() === 'Firefox')
) {
} else if (port.name === CONNECTION_TYPES.POPUP && isExtensionSender) {
type = CONNECTION_TYPES.POPUP;
} else {
type = CONNECTION_TYPES.OTHER;
Expand Down

1 comment on commit 041305b

@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.