Skip to content

Commit

Permalink
fix scrollbars on windows + stuff (#121)
Browse files Browse the repository at this point in the history
* fixed horizontal scroll on incoming action

* fixed login redirect

* fix resizing on firefox

* rejected default status
  • Loading branch information
ChriLnth authored Jul 21, 2021
1 parent 627948f commit c54a918
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 131 deletions.
256 changes: 136 additions & 120 deletions source/Background/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,68 +74,76 @@ backgroundController.exposeController('isConnected', async (opts, url) => secure
});
}));

backgroundController.exposeController('requestConnect', async (opts, domainUrl, name, icon) => secureController(opts.callback, async () => {
const { message, sender } = opts;
storage.get('apps', (response) => {
const apps = {
...response.apps,
[domainUrl]: {
backgroundController.exposeController(
'requestConnect',
async (opts, domainUrl, name, icon) => secureController(opts.callback, async () => {
const { message, sender } = opts;
storage.get('apps', (response) => {
const apps = {
...response.apps,
[domainUrl]: {
url: domainUrl,
name,
status: CONNECTION_STATUS.pending,
icon,
},
};

storage.set({ apps });
});

const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId: message.data.data.id,
portId: sender.id,
url: domainUrl,
name,
status: CONNECTION_STATUS.pending,
icon,
type: 'connect',
},
};

storage.set({ apps });
});

const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId: message.data.data.id,
portId: sender.id,
url: domainUrl,
icon,
type: 'connect',
},
});
});

const height = keyring?.isUnlocked
? SIZES.appConnectHeight
: SIZES.loginHeight;
const height = keyring?.isUnlocked
? SIZES.appConnectHeight
: SIZES.loginHeight;

extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height,
});
}));
extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height,
});
}),
);

backgroundController.exposeController('handleAppConnect', async (opts, url, status, callId, portId) => secureController(opts.callback, async () => {
const { callback } = opts;
backgroundController.exposeController(
'handleAppConnect',
async (opts, url, status, callId, portId) => secureController(opts.callback, async () => {
const { callback } = opts;

storage.get('apps', (response) => {
const apps = response.apps || {};
storage.get('apps', (response) => {
const apps = response.apps || {};

const newApps = Object.keys(apps).reduce((obj, key) => {
const newObj = { ...obj };
newObj[key] = apps[key];
if (key === url) {
newObj[key].status = status;
newObj[key].date = new Date().toISOString();
}
const newApps = Object.keys(apps).reduce((obj, key) => {
const newObj = { ...obj };
newObj[key] = apps[key];
if (key === url) {
newObj[key].status = status || CONNECTION_STATUS.rejected;
newObj[key].date = new Date().toISOString();
}

return newObj;
}, {});
return newObj;
}, {});

storage.set({ apps: newApps });
});
storage.set({ apps: newApps });
});

callback(null, true);
callback(null, status === CONNECTION_STATUS.accepted, [{ portId, callId }]);
}));
callback(null, true);
callback(null, status === CONNECTION_STATUS.accepted, [
{ portId, callId },
]);
}),
);

const requestBalance = async (accountId, callback) => {
const getBalance = getKeyringHandler(HANDLER_TYPES.GET_BALANCE, keyring);
Expand All @@ -147,37 +155,42 @@ const requestBalance = async (accountId, callback) => {
}
};

backgroundController.exposeController('requestBalance', async (opts, metadata, accountId) => secureController(opts.callback, async () => {
const { callback, message, sender } = opts;

storage.get('apps', async (state) => {
if (state?.apps?.[metadata.url]?.status === CONNECTION_STATUS.accepted) {
if (!keyring.isUnlocked) {
const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId: message.data.data.id,
portId: sender.id,
type: 'balance',
argsJson: accountId,
metadataJson: JSON.stringify(metadata),
},
});
backgroundController.exposeController(
'requestBalance',
async (opts, metadata, accountId) => secureController(opts.callback, async () => {
const { callback, message, sender } = opts;

extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height: SIZES.loginHeight,
});
storage.get('apps', async (state) => {
if (
state?.apps?.[metadata.url]?.status === CONNECTION_STATUS.accepted
) {
if (!keyring.isUnlocked) {
const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId: message.data.data.id,
portId: sender.id,
type: 'balance',
argsJson: accountId,
metadataJson: JSON.stringify(metadata),
},
});

extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height: SIZES.loginHeight,
});
} else {
requestBalance(accountId, callback);
}
} else {
requestBalance(accountId, callback);
callback(ERRORS.CONNECTION_ERROR, null);
}
} else {
callback(ERRORS.CONNECTION_ERROR, null);
}
});
}));
});
}),
);

backgroundController.exposeController(
'handleRequestBalance',
Expand Down Expand Up @@ -205,45 +218,50 @@ backgroundController.exposeController(
},
);

backgroundController.exposeController('requestTransfer', async (opts, metadata, args) => secureController(opts.callback, async () => {
const { message, sender, callback } = opts;

const { id: callId } = message.data.data;
const { id: portId } = sender;
storage.get('apps', async (state) => {
if (state?.apps?.[metadata.url]?.status === CONNECTION_STATUS.accepted) {
const argsError = validateTransferArgs(args);
if (argsError) {
callback(argsError, null);
return;
backgroundController.exposeController(
'requestTransfer',
async (opts, metadata, args) => secureController(opts.callback, async () => {
const { message, sender, callback } = opts;

const { id: callId } = message.data.data;
const { id: portId } = sender;
storage.get('apps', async (state) => {
if (
state?.apps?.[metadata.url]?.status === CONNECTION_STATUS.accepted
) {
const argsError = validateTransferArgs(args);
if (argsError) {
callback(argsError, null);
return;
}
const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId,
portId,
metadataJson: JSON.stringify(metadata),
argsJson: JSON.stringify(args),
type: 'transfer',
},
});

const height = keyring?.isUnlocked
? SIZES.detailHeightSmall
: SIZES.loginHeight;
extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height,
top: 65,
left: metadata.pageWidth - SIZES.width,
});
} else {
callback(ERRORS.CONNECTION_ERROR, null);
}
const url = qs.stringifyUrl({
url: 'notification.html',
query: {
callId,
portId,
metadataJson: JSON.stringify(metadata),
argsJson: JSON.stringify(args),
type: 'transfer',
},
});

const height = keyring?.isUnlocked
? SIZES.detailHeightSmall
: SIZES.loginHeight;
extension.windows.create({
url,
type: 'popup',
width: SIZES.width,
height,
top: 65,
left: metadata.pageWidth - SIZES.width,
});
} else {
callback(ERRORS.CONNECTION_ERROR, null);
}
});
}));
});
}),
);

backgroundController.exposeController(
'handleRequestTransfer',
Expand All @@ -254,9 +272,7 @@ backgroundController.exposeController(
// Answer this callback no matter if the transfer succeeds or not.
callback(null, true);
if (transfer?.status === 'declined') {
callback(ERRORS.TRANSACTION_REJECTED, null, [
{ portId, callId },
]);
callback(ERRORS.TRANSACTION_REJECTED, null, [{ portId, callId }]);
} else {
const getBalance = getKeyringHandler(HANDLER_TYPES.GET_BALANCE, keyring);
const sendICP = getKeyringHandler(HANDLER_TYPES.SEND_ICP, keyring);
Expand Down
6 changes: 5 additions & 1 deletion source/Background/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export default {
CONNECTION_ERROR: { code: 401, message: 'You are not connected. You must call window.ic.plug.requestConnect() and have the user accept the popup before you call this method.' },
CONNECTION_ERROR: {
code: 401,
message:
'You are not connected. You must call window.ic.plug.requestConnect() and have the user accept the popup before you call this method.',
},
BALANCE_ERROR: { code: 400, message: 'Insufficient balance' },
TRANSACTION_REJECTED: { code: 401, message: 'The transactions was rejected' },
INITIALIZED_ERROR: { code: 403, message: 'Plug must be initialized.' },
Expand Down
3 changes: 0 additions & 3 deletions source/ContentScript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ serverRPC.start();

injectScript(null, INPAGE_SCRIPT);

/* eslint-disable no-console */
console.log('helloworld from content script');

export {};
8 changes: 7 additions & 1 deletion source/Pages/Notification/components/AppConnection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { CONNECTION_STATUS } from '@shared/constants/connectionStatus';
import store from '@redux/store';
import { Layout } from '@components';
import extension from 'extensionizer';
import initConfig from '../../../../locales';
import SIZES from '../Transfer/constants';
import useStyles from './styles';
Expand Down Expand Up @@ -50,7 +51,12 @@ const AppConnection = () => {
// onClickHandler(CONNECTION_STATUS.rejected);
// };

window.resizeTo(SIZES.width, SIZES.appConnectHeight);
extension.windows.update(
extension.windows.WINDOW_ID_CURRENT,
{
height: SIZES.appConnectHeight,
},
);

return (
<Provider store={store}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormItem } from '@ui';
import extension from 'extensionizer';
import useStyles from '../styles';
import SIZES from '../constants';

const Data = ({ data, principalId }) => {
const classes = useStyles();

window.resizeTo(SIZES.width, principalId
? SIZES.dataHeightBig
: SIZES.dataHeightSmall);
extension.windows.update(
extension.windows.WINDOW_ID_CURRENT,
{
height: principalId
? SIZES.dataHeightBig
: SIZES.dataHeightSmall,
},
);

return (
<div className={classes.innerContainer}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Typography } from '@material-ui/core';
import { CURRENCIES } from '@shared/constants/currencies';
import { E8S_PER_ICP } from '@background/Keyring';
import NumberFormat from 'react-number-format';
import extension from 'extensionizer';
import useStyles from '../styles';
import SIZES from '../constants';

Expand All @@ -19,9 +20,14 @@ const Details = ({
const amount = e8s / E8S_PER_ICP;
const value = (amount * icpPrice);

window.resizeTo(SIZES.width, requestCount > 1
? SIZES.detailsHeightBig
: SIZES.detailHeightSmall);
extension.windows.update(
extension.windows.WINDOW_ID_CURRENT,
{
height: requestCount > 1
? SIZES.detailsHeightBig
: SIZES.detailHeightSmall,
},
);

return (
<div className={classes.innerContainer}>
Expand Down

0 comments on commit c54a918

Please sign in to comment.