Skip to content

Commit

Permalink
feat(suite-desktop-core): deeplink and basic styling to http-receiver…
Browse files Browse the repository at this point in the history
… pages
  • Loading branch information
mroz22 committed Jul 1, 2024
1 parent 04491cc commit fdff6c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/suite-desktop-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@sentry/electron": "^4.17.0",
"@suite-common/message-system": "workspace:*",
"@suite-common/sentry": "workspace:*",
"@suite-common/suite-constants": "workspace:^",
"@suite-common/suite-types": "workspace:*",
"@suite-common/suite-utils": "workspace:*",
"@suite-common/wallet-config": "workspace:*",
Expand Down
39 changes: 32 additions & 7 deletions packages/suite-desktop-core/src/libs/http-receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as url from 'url';

import { xssFilters } from '@trezor/utils';
import { HttpServer, allowReferers } from '@trezor/node-utils';
import { trezorLogo } from '@suite-common/suite-constants';

import { HTTP_ORIGINS_DEFAULT } from './constants';
import { convertILoggerToLog } from '../utils/IloggerToLog';
Expand All @@ -21,16 +22,42 @@ interface Events {
'spend/message': (event: Partial<MessageEvent>) => void;
}

const applyTemplate = (content: string, options?: TemplateOptions) => {
const applyTemplate = (content = 'You may now close this window.', options?: TemplateOptions) => {
const template = `
<!DOCTYPE html>
<html>
<head>
<title>${options?.title ?? 'Trezor Suite'}</title>
${options?.script || ''}
<style>
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
a {
text-decoration: none;
cursor: pointer;
color: #171717;
font-weight: 500;
display: inline-flex;
align-items: center;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<img style="margin-bottom:40px" alt="trezor logo" src="data:image/png;base64, ${trezorLogo}" />
${content}
<a style="margin-top:40px" href="trezorsuite://">Go back to Trezor Suite</a>
</body>
</html>
`;
Expand Down Expand Up @@ -68,7 +95,7 @@ export const createHttpReceiver = () => {
}
</script>
`;
const template = applyTemplate('You may now close this window.', { script });
const template = applyTemplate(undefined, { script });
response.end(template);
},
]);
Expand All @@ -81,7 +108,7 @@ export const createHttpReceiver = () => {
httpReceiver.emit('buy/redirect', query.p.toString());
}

const template = applyTemplate('You may now close this window.');
const template = applyTemplate();
response.end(template);
},
]);
Expand Down Expand Up @@ -126,7 +153,7 @@ export const createHttpReceiver = () => {
httpReceiver.emit('sell/redirect', query.p.toString());
}

const template = applyTemplate('You may now close this window.');
const template = applyTemplate();
response.end(template);
},
]);
Expand All @@ -143,8 +170,6 @@ export const createHttpReceiver = () => {
height: 100%;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
font-family: sans-serif;
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -207,7 +232,7 @@ export const createHttpReceiver = () => {
data: Array.isArray(query.data) ? query.data.join(',') : query.data,
});

const template = applyTemplate('You may now close this window.');
const template = applyTemplate();
response.end(template);
},
]);
Expand Down
3 changes: 3 additions & 0 deletions packages/suite-desktop-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"path": "../../suite-common/message-system"
},
{ "path": "../../suite-common/sentry" },
{
"path": "../../suite-common/suite-constants"
},
{
"path": "../../suite-common/suite-types"
},
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8725,7 +8725,7 @@ __metadata:
languageName: unknown
linkType: soft

"@suite-common/suite-constants@workspace:*, @suite-common/suite-constants@workspace:suite-common/suite-constants":
"@suite-common/suite-constants@workspace:*, @suite-common/suite-constants@workspace:^, @suite-common/suite-constants@workspace:suite-common/suite-constants":
version: 0.0.0-use.local
resolution: "@suite-common/suite-constants@workspace:suite-common/suite-constants"
dependencies:
Expand Down Expand Up @@ -11126,6 +11126,7 @@ __metadata:
"@sentry/webpack-plugin": "npm:^2.14.0"
"@suite-common/message-system": "workspace:*"
"@suite-common/sentry": "workspace:*"
"@suite-common/suite-constants": "workspace:^"
"@suite-common/suite-types": "workspace:*"
"@suite-common/suite-utils": "workspace:*"
"@suite-common/wallet-config": "workspace:*"
Expand Down

0 comments on commit fdff6c2

Please sign in to comment.