Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet-ext: disconnect dapp popup #4714

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,235 changes: 1,098 additions & 137 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Binary file modified wallet/font-icons/output/sui-icons.eot
Binary file not shown.
70 changes: 36 additions & 34 deletions wallet/font-icons/output/sui-icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@
.sui-icons-arrow-left:before { content: "\ea0a"; }
.sui-icons-arrow-right:before { content: "\ea0b"; }
.sui-icons-checkmark:before { content: "\ea0c"; }
.sui-icons-clipboard:before { content: "\ea0d"; }
.sui-icons-close:before { content: "\ea0e"; }
.sui-icons-coins:before { content: "\ea0f"; }
.sui-icons-globe:before { content: "\ea10"; }
.sui-icons-hand-coins:before { content: "\ea11"; }
.sui-icons-history:before { content: "\ea12"; }
.sui-icons-logout:before { content: "\ea13"; }
.sui-icons-nfts:before { content: "\ea14"; }
.sui-icons-percentage-polygon:before { content: "\ea15"; }
.sui-icons-person:before { content: "\ea16"; }
.sui-icons-search:before { content: "\ea17"; }
.sui-icons-sui-chevron-right:before { content: "\ea18"; }
.sui-icons-sui-logo-icon:before { content: "\ea19"; }
.sui-icons-sui-logo-txt:before { content: "\ea1a"; }
.sui-icons-swap:before { content: "\ea1b"; }
.sui-icons-tokens:before { content: "\ea1c"; }
.sui-icons-version-icon:before { content: "\ea1d"; }
.sui-icons-chevron-down:before { content: "\ea0d"; }
.sui-icons-clipboard:before { content: "\ea0e"; }
.sui-icons-close:before { content: "\ea0f"; }
.sui-icons-coins:before { content: "\ea10"; }
.sui-icons-globe:before { content: "\ea11"; }
.sui-icons-hand-coins:before { content: "\ea12"; }
.sui-icons-history:before { content: "\ea13"; }
.sui-icons-logout:before { content: "\ea14"; }
.sui-icons-nfts:before { content: "\ea15"; }
.sui-icons-percentage-polygon:before { content: "\ea16"; }
.sui-icons-person:before { content: "\ea17"; }
.sui-icons-search:before { content: "\ea18"; }
.sui-icons-sui-chevron-right:before { content: "\ea19"; }
.sui-icons-sui-logo-icon:before { content: "\ea1a"; }
.sui-icons-sui-logo-txt:before { content: "\ea1b"; }
.sui-icons-swap:before { content: "\ea1c"; }
.sui-icons-tokens:before { content: "\ea1d"; }
.sui-icons-version-icon:before { content: "\ea1e"; }

$sui-icons-Buy: "\ea01";
$sui-icons-Download: "\ea02";
Expand All @@ -57,21 +58,22 @@ $sui-icons-apps: "\ea09";
$sui-icons-arrow-left: "\ea0a";
$sui-icons-arrow-right: "\ea0b";
$sui-icons-checkmark: "\ea0c";
$sui-icons-clipboard: "\ea0d";
$sui-icons-close: "\ea0e";
$sui-icons-coins: "\ea0f";
$sui-icons-globe: "\ea10";
$sui-icons-hand-coins: "\ea11";
$sui-icons-history: "\ea12";
$sui-icons-logout: "\ea13";
$sui-icons-nfts: "\ea14";
$sui-icons-percentage-polygon: "\ea15";
$sui-icons-person: "\ea16";
$sui-icons-search: "\ea17";
$sui-icons-sui-chevron-right: "\ea18";
$sui-icons-sui-logo-icon: "\ea19";
$sui-icons-sui-logo-txt: "\ea1a";
$sui-icons-swap: "\ea1b";
$sui-icons-tokens: "\ea1c";
$sui-icons-version-icon: "\ea1d";
$sui-icons-chevron-down: "\ea0d";
$sui-icons-clipboard: "\ea0e";
$sui-icons-close: "\ea0f";
$sui-icons-coins: "\ea10";
$sui-icons-globe: "\ea11";
$sui-icons-hand-coins: "\ea12";
$sui-icons-history: "\ea13";
$sui-icons-logout: "\ea14";
$sui-icons-nfts: "\ea15";
$sui-icons-percentage-polygon: "\ea16";
$sui-icons-person: "\ea17";
$sui-icons-search: "\ea18";
$sui-icons-sui-chevron-right: "\ea19";
$sui-icons-sui-logo-icon: "\ea1a";
$sui-icons-sui-logo-txt: "\ea1b";
$sui-icons-swap: "\ea1c";
$sui-icons-tokens: "\ea1d";
$sui-icons-version-icon: "\ea1e";

37 changes: 20 additions & 17 deletions wallet/font-icons/output/sui-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions wallet/font-icons/output/sui-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum SuiIcons {
ArrowLeft = "sui-icons-arrow-left",
ArrowRight = "sui-icons-arrow-right",
Checkmark = "sui-icons-checkmark",
ChevronDown = "sui-icons-chevron-down",
Clipboard = "sui-icons-clipboard",
Close = "sui-icons-close",
Coins = "sui-icons-coins",
Expand All @@ -33,6 +34,6 @@ export enum SuiIcons {
VersionIcon = "sui-icons-version-icon"
}

export type SuiIconsClassname = "sui-icons-Buy" | "sui-icons-Download" | "sui-icons-Info" | "sui-icons-Plus" | "sui-icons-Preview" | "sui-icons-ThumbsUp" | "sui-icons-Union" | "sui-icons-activity" | "sui-icons-apps" | "sui-icons-arrow-left" | "sui-icons-arrow-right" | "sui-icons-checkmark" | "sui-icons-clipboard" | "sui-icons-close" | "sui-icons-coins" | "sui-icons-globe" | "sui-icons-hand-coins" | "sui-icons-history" | "sui-icons-logout" | "sui-icons-nfts" | "sui-icons-percentage-polygon" | "sui-icons-person" | "sui-icons-search" | "sui-icons-sui-chevron-right" | "sui-icons-sui-logo-icon" | "sui-icons-sui-logo-txt" | "sui-icons-swap" | "sui-icons-tokens" | "sui-icons-version-icon"
export type SuiIconsIcon = "Buy" | "Download" | "Info" | "Plus" | "Preview" | "ThumbsUp" | "Union" | "activity" | "apps" | "arrow-left" | "arrow-right" | "checkmark" | "clipboard" | "close" | "coins" | "globe" | "hand-coins" | "history" | "logout" | "nfts" | "percentage-polygon" | "person" | "search" | "sui-chevron-right" | "sui-logo-icon" | "sui-logo-txt" | "swap" | "tokens" | "version-icon"
export const SuiIconsPrefix = "sui-icons-"
export type SuiIconsClassname = "sui-icons-Buy" | "sui-icons-Download" | "sui-icons-Info" | "sui-icons-Plus" | "sui-icons-Preview" | "sui-icons-ThumbsUp" | "sui-icons-Union" | "sui-icons-activity" | "sui-icons-apps" | "sui-icons-arrow-left" | "sui-icons-arrow-right" | "sui-icons-checkmark" | "sui-icons-chevron-down" | "sui-icons-clipboard" | "sui-icons-close" | "sui-icons-coins" | "sui-icons-globe" | "sui-icons-hand-coins" | "sui-icons-history" | "sui-icons-logout" | "sui-icons-nfts" | "sui-icons-percentage-polygon" | "sui-icons-person" | "sui-icons-search" | "sui-icons-sui-chevron-right" | "sui-icons-sui-logo-icon" | "sui-icons-sui-logo-txt" | "sui-icons-swap" | "sui-icons-tokens" | "sui-icons-version-icon"
export type SuiIconsIcon = "Buy" | "Download" | "Info" | "Plus" | "Preview" | "ThumbsUp" | "Union" | "activity" | "apps" | "arrow-left" | "arrow-right" | "checkmark" | "chevron-down" | "clipboard" | "close" | "coins" | "globe" | "hand-coins" | "history" | "logout" | "nfts" | "percentage-polygon" | "person" | "search" | "sui-chevron-right" | "sui-logo-icon" | "sui-logo-txt" | "swap" | "tokens" | "version-icon"
export const SuiIconsPrefix = "sui-icons-"
Binary file modified wallet/font-icons/output/sui-icons.ttf
Binary file not shown.
Binary file modified wallet/font-icons/output/sui-icons.woff
Binary file not shown.
Binary file modified wallet/font-icons/output/sui-icons.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions wallet/font-icons/svgs/chevron-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
},
"dependencies": {
"@mysten/sui.js": "workspace:*",
"@popperjs/core": "^2.11.6",
Copy link
Contributor

Choose a reason for hiding this comment

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

Popper has a successor called Floating UI, which I'd use if you can instead: https://floating-ui.com/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh cool looks fancy! I am not familiar and I have limited time today, do you think changing it in another PR would be ok? (I will create an issue to track it)

"@reduxjs/toolkit": "^1.8.3",
"@scure/bip32": "^1.1.0",
"bip39-light": "^1.0.7",
Expand All @@ -89,6 +90,7 @@
"react-dom": "^18.2.0",
"react-intl": "^6.0.5",
"react-number-format": "^4.9.3",
"react-popper": "^2.3.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-textarea-autosize": "^8.3.4",
Expand Down
10 changes: 10 additions & 0 deletions wallet/src/background/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ class Permissions {
);
}

public async delete(origin: string) {
const allPermissions = await this.getPermissions();
if (origin in allPermissions) {
delete allPermissions[origin];
await Browser.storage.local.set({
[PERMISSIONS_STORAGE_KEY]: allPermissions,
});
}
}

private async createPermissionRequest(
origin: string,
permissionTypes: readonly PermissionType[],
Expand Down
4 changes: 4 additions & 0 deletions wallet/src/background/connections/UiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isTransactionRequestResponse } from '_payloads/transactions/ui/Transact
import Permissions from '_src/background/Permissions';
import Tabs from '_src/background/Tabs';
import Transactions from '_src/background/Transactions';
import { isDisconnectApp } from '_src/shared/messaging/messages/payloads/permissions/DisconnectApp';

import type { Message } from '_messages';
import type { PortChannelName } from '_messaging/PortChannelName';
Expand Down Expand Up @@ -68,6 +69,9 @@ export class UiConnection extends Connection {
Object.values(await Transactions.getTransactionRequests()),
id
);
} else if (isDisconnectApp(payload)) {
await Permissions.delete(payload.origin);
this.send(createMessage({ type: 'done' }, id));
}
}

Expand Down
4 changes: 3 additions & 1 deletion wallet/src/shared/messaging/messages/payloads/BasePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export type PayloadType =
| 'get-transaction-requests'
| 'get-transaction-requests-response'
| 'transaction-request-response'
| 'update-active-origin';
| 'update-active-origin'
| 'disconnect-app'
| 'done';

export interface BasePayload {
type: PayloadType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { isBasePayload } from '_payloads';

import type { BasePayload, Payload } from '_payloads';

export interface DisconnectApp extends BasePayload {
type: 'disconnect-app';
origin: string;
}

export function isDisconnectApp(payload: Payload): payload is DisconnectApp {
return isBasePayload(payload) && payload.type === 'disconnect-app';
}
9 changes: 9 additions & 0 deletions wallet/src/ui/app/background-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
GetPermissionRequests,
PermissionResponse,
} from '_payloads/permissions';
import type { DisconnectApp } from '_payloads/permissions/DisconnectApp';
import type { GetTransactionRequests } from '_payloads/transactions/ui/GetTransactionRequests';
import type { TransactionRequestResponse } from '_payloads/transactions/ui/TransactionRequestResponse';
import type { AppDispatch } from '_store';
Expand Down Expand Up @@ -94,6 +95,14 @@ export class BackgroundClient {
);
}

public async disconnectApp(origin: string) {
await lastValueFrom(
this.sendMessage(
createMessage<DisconnectApp>({ type: 'disconnect-app', origin })
).pipe(take(1))
);
}

private handleIncomingMessage(msg: Message) {
if (!this._initialized || !this._dispatch) {
throw new Error(
Expand Down
10 changes: 5 additions & 5 deletions wallet/src/ui/app/hooks/useOnClickOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const useOnClickOutside = <T extends HTMLElement = HTMLElement>(
useEffect(() => {
const listener = (event: Event) => {
const el = ref?.current;
if (!el || el.contains((event?.target as Node) || null)) {
if (!el || el.contains(event?.target as Node)) {
return;
}

handler(event); // Call the handler only if the click is outside of the element passed.
};

document.addEventListener('mousedown', listener);
document.addEventListener('touchstart', listener);
document.addEventListener('click', listener, true);
document.addEventListener('touchstart', listener, true);

return () => {
document.removeEventListener('mousedown', listener);
document.removeEventListener('touchstart', listener);
document.removeEventListener('click', listener, true);
document.removeEventListener('touchstart', listener, true);
};
}, [ref, handler]); // Reload only if ref or handler changes
};
Expand Down
85 changes: 84 additions & 1 deletion wallet/src/ui/app/shared/dapp-status/DappStatus.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@use '_values/colors';
@use '_utils';

.wrapper {
display: contents;
}

.container {
display: flex;
flex-flow: row;
Expand All @@ -14,6 +18,7 @@
cursor: default;
overflow: hidden;
flex: 0 1 auto;
transition: all 150ms ease-in-out;

@include utils.typography('Primary/BodySmall-M');

Expand All @@ -29,7 +34,7 @@
}

&:active,
&.acive {
&.active {
color: colors.$sui-blue;
border: none;
}
Expand All @@ -50,3 +55,81 @@

@include utils.overflow-ellipsis;
}

.chevron {
margin-left: 6px;
font-size: 11px;
}

.popup {
position: absolute;
background: colors.$gray-100;
border-radius: 6px;
padding: 10px 12px;
z-index: 999;
max-width: 55%;
}

.popup-content {
display: flex;
flex-flow: column nowrap;
align-items: center;
}

.popup-arrow {
position: absolute;
z-index: -1;
top: -5px;

&::before {
content: '';
background: colors.$gray-100;
transform: rotate(45deg);
height: 12px;
width: 12px;
display: block;
}
}

.origin-container {
display: flex;
flex-flow: row nowrap;
align-items: center;
}

.favicon {
width: 22px;
height: 22px;
border-radius: 6px;
background-color: colors.$gray-85;
margin-right: 8px;
padding: 2px;
}

.origin-text {
@include utils.overflow-ellipsis;
@include utils.typography('Primary/SubtitleSmall-M');

color: colors.$success;
}

.origin-url {
@include utils.typography('Primary/BodySmall-SB');
}

.divider {
height: 1px;
background-color: colors.$gray-90;
margin: 8px 0;
align-self: stretch;
}

.disconnect {
background: none;
outline: none;
border: none;
color: colors.$issue;
cursor: pointer;

@include utils.typography('Primary/BodySmall-M');
}
18 changes: 18 additions & 0 deletions wallet/src/ui/app/shared/dapp-status/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { createAsyncThunk } from '@reduxjs/toolkit';

import type { AppThunkConfig } from '_redux/store/thunk-extras';

export const appDisconnect = createAsyncThunk<
void,
{ origin: string },
AppThunkConfig
>(
'dapp-status-app-disconnect',
async ({ origin }, { extra: { background } }) => {
await background.disconnectApp(origin);
await background.sendGetPermissionRequests();
}
);
Loading