Skip to content

Commit

Permalink
added app pagelink (MystenLabs#4978)
Browse files Browse the repository at this point in the history
* added app pagelink

* rebase

* rm size hight 90vh

* comment update
  • Loading branch information
Jibz1 authored Oct 14, 2022
1 parent 0d7b189 commit 0cac217
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions apps/wallet/src/background/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class Permissions {
permissionTypes,
connection.originFavIcon,
requestMsgID,
connection.pagelink,
existingPermission
);
await new Window(Permissions.getUiUrl(pRequest.id)).show();
Expand Down Expand Up @@ -242,6 +243,7 @@ class Permissions {
permissionTypes: readonly PermissionType[],
favIcon: string | undefined,
requestMsgID: string,
pagelink?: string | undefined,
existingPermission?: Permission | null
): Promise<Permission> {
let permissionToStore: Permission;
Expand All @@ -268,6 +270,7 @@ class Permissions {
createdDate: new Date().toISOString(),
origin,
favIcon,
pagelink,
permissions: permissionTypes as PermissionType[],
responseDate: null,
requestMsgID,
Expand Down
10 changes: 10 additions & 0 deletions apps/wallet/src/background/connections/ContentScriptConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export class ContentScriptConnection extends Connection {
public static readonly CHANNEL: PortChannelName =
'sui_content<->background';
public readonly origin: string;
public readonly pagelink?: string | undefined;
public readonly originFavIcon: string | undefined;

constructor(port: Runtime.Port) {
super(port);
this.origin = this.getOrigin(port);
this.pagelink = this.getAppUrl(port);
this.originFavIcon = port.sender?.tab?.favIconUrl;
}

Expand Down Expand Up @@ -160,6 +162,14 @@ export class ContentScriptConnection extends Connection {
);
}

// optional field for the app link.
private getAppUrl(port: Runtime.Port) {
if (port.sender?.url) {
return new URL(port.sender.url).href;
}
return undefined;
}

private sendError<Error extends ErrorPayload>(
error: Error,
responseForID?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Permission {
name?: string;
id: string;
origin: string;
pagelink?: string;
pagelink?: string | undefined;
favIcon: string | undefined;
accounts: SuiAddress[];
allowed: boolean | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function ConnectedDapps() {
name: name,
icon: appData?.favIcon,
link: appData.origin,
pagelink: appData.pagelink,
linkLabel: appData.origin.replace('https://', ''),
description: '',
id: appData.id,
Expand Down
6 changes: 4 additions & 2 deletions apps/wallet/src/ui/app/components/sui-apps/DisconnectApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type DisconnectAppProps = {
address?: SuiAddress;
permissions: string[];
disconnect?: boolean;
pageLink?: string;
setShowDisconnectApp: (showModal: boolean) => void;
};

Expand All @@ -41,6 +42,7 @@ function DisconnectApp({
account,
id,
permissions,
pageLink,
setShowDisconnectApp,
}: DisconnectAppProps) {
const [showModal] = useState(true);
Expand Down Expand Up @@ -76,7 +78,7 @@ function DisconnectApp({
<div className={st.info}>
<div className={st.name}>{name}</div>
<ExternalLink
href={link}
href={pageLink || link}
title={name}
className={st.appLink}
showIcon={false}
Expand Down Expand Up @@ -131,7 +133,7 @@ function DisconnectApp({
<span>Disconnect</span>
</Button>
<ExternalLink
href={link}
href={pageLink || link}
title={name}
className={cl('btn', st.ctaBtn, st.view)}
showIcon={false}
Expand Down
5 changes: 4 additions & 1 deletion apps/wallet/src/ui/app/components/sui-apps/SuiApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type SuiAppProps = {
link: string;
account?: string;
id?: string;
pageLink?: string;
permissions: string[];
disconnect?: boolean;
};
Expand Down Expand Up @@ -56,6 +57,7 @@ function SuiApp({
tags,
id,
account,
pageLink,
permissions,
disconnect,
}: SuiAppProps) {
Expand All @@ -66,6 +68,7 @@ function SuiApp({
link,
id,
permissions,
pageLink,
};

const originLabel = useMiddleEllipsis(
Expand Down Expand Up @@ -135,7 +138,7 @@ function SuiApp({
</>
) : (
<ExternalLink
href={link}
href={pageLink || link}
title={name}
className={st.ecosystemApp}
showIcon={false}
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/ui/app/components/sui-apps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function AppsPlayGround() {
icon: isConnected.favIcon || app.icon,
// instance where the origin has a trailing slash and the app.link does not
link: isConnected.origin,
pageLink: isConnected.pagelink,
}
: {}),
};
Expand Down

0 comments on commit 0cac217

Please sign in to comment.