Skip to content

Commit d56c42c

Browse files
jamaljsrguggero
authored andcommitted
sessions: disable copying pairing phrases that are in use
1 parent 171aca2 commit d56c42c

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

app/src/components/base/icons.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { ReactComponent as UserPlusIcon } from 'assets/icons/user-plus.svg';
3434
interface IconProps {
3535
size?: 'x-small' | 'small' | 'medium' | 'large';
3636
onClick?: () => void;
37+
disabled?: boolean;
3738
}
3839

3940
const Icon = styled.span<IconProps>`
@@ -52,6 +53,12 @@ const Icon = styled.span<IconProps>`
5253
}
5354
`}
5455
56+
${props =>
57+
props.disabled &&
58+
`
59+
color: ${props.theme.colors.lightBlue};
60+
`}
61+
5562
${props =>
5663
props.size === 'x-small' &&
5764
`

app/src/components/connect/SessionRow.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const RowHeader: React.FC = () => {
7777
{l('type')}
7878
</SortableHeader>
7979
</HeaderColumn>
80-
<HeaderColumn right>
80+
<HeaderColumn>
8181
<SortableHeader<Session>
8282
field="state"
8383
sort={settingsStore.sessionSort}
@@ -86,6 +86,15 @@ const RowHeader: React.FC = () => {
8686
{l('state')}
8787
</SortableHeader>
8888
</HeaderColumn>
89+
<HeaderColumn>
90+
<SortableHeader<Session>
91+
field="expiry"
92+
sort={settingsStore.sessionSort}
93+
onSort={settingsStore.setSessionSort}
94+
>
95+
{l('expiry')}
96+
</SortableHeader>
97+
</HeaderColumn>
8998
<ActionColumn />
9099
</HeaderRow>
91100
);
@@ -114,16 +123,23 @@ const SessionRow: React.FC<Props> = ({ session, style }) => {
114123
return (
115124
<Row style={style}>
116125
<ActionColumn>
117-
<Tip overlay={l('copy')}>
118-
<Copy onClick={handleCopy} />
119-
</Tip>
126+
{session.isPaired ? (
127+
<Tip overlay={l('paired')}>
128+
<Copy disabled />
129+
</Tip>
130+
) : (
131+
<Tip overlay={l('copy')}>
132+
<Copy onClick={handleCopy} />
133+
</Tip>
134+
)}
120135
</ActionColumn>
121136
<Column cols={3}>{session.label}</Column>
122137
<Column>{session.typeLabel}</Column>
123-
<Column right>{session.stateLabel}</Column>
138+
<Column>{session.pairedLabel}</Column>
139+
<Column>{session.expiryLabel}</Column>
124140
<ActionColumn>
125141
<Tip overlay={l('revoke')}>
126-
<CloseIcon onClick={handleRevoke} />
142+
<CloseIcon size="large" onClick={handleRevoke} />
127143
</Tip>
128144
</ActionColumn>
129145
</Row>

app/src/i18n/locales/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
"cmps.connect.SessionRowHeader.label": "Label",
4747
"cmps.connect.SessionRowHeader.type": "Type",
4848
"cmps.connect.SessionRowHeader.state": "State",
49+
"cmps.connect.SessionRowHeader.expiry": "Expiry",
4950
"cmps.connect.SessionRow.copy": "Copy Pairing Phrase",
51+
"cmps.connect.SessionRow.paired": "This Pairing Phrase has already been used by a client",
5052
"cmps.connect.SessionRow.revoke": "Revoke Session",
5153
"cmps.history.HistoryPage.backText": "Lightning Loop",
5254
"cmps.history.HistoryPage.pageTitle": "History",

app/src/store/models/session.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { makeAutoObservable } from 'mobx';
22
import * as LIT from 'types/generated/lit-sessions_pb';
33
import { SortParams } from 'types/state';
44
import formatDate from 'date-fns/format';
5+
import { MAX_DATE } from 'util/constants';
56
import { hex } from 'util/strings';
67
import { Store } from 'store/store';
78

@@ -65,7 +66,9 @@ export default class Session {
6566

6667
/** The date this session will expire as formatted string */
6768
get expiryLabel() {
68-
return formatDate(this.expiry, 'MMM d, h:mm a');
69+
return this.expiry.getTime() === MAX_DATE.getTime()
70+
? 'Never'
71+
: formatDate(this.expiry, 'MMM d, yyyy h:mm a');
6972
}
7073

7174
/** True if the session is not revoked or expired */
@@ -76,6 +79,16 @@ export default class Session {
7679
);
7780
}
7881

82+
/** True if the session has had a client connect to it */
83+
get isPaired() {
84+
return this.remotePublicKey !== '';
85+
}
86+
87+
/** The paired status as a string */
88+
get pairedLabel() {
89+
return this.isPaired ? 'In Use' : 'Created';
90+
}
91+
7992
/**
8093
* Updates this session model using data provided from the LIT GRPC api
8194
*/

app/src/store/stores/sessionStore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ export default class SessionStore {
9999
* @param label the user defined label for this session
100100
* @param type the type of session being created (admin, read-only, etc)
101101
* @param expiry how long the session should be valid for
102-
* @param mailboxServerAddr the address where the mailbox server is reachable
103-
* @param devServer whether the mailbox server is a dev server that has no valid TLS cert
104102
*/
105103
async addSession(
106104
label: string,

0 commit comments

Comments
 (0)