Skip to content
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
19 changes: 14 additions & 5 deletions app/src/components/connect/AddSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FormField from 'components/common/FormField';
import FormInput from 'components/common/FormInput';
import FormSelect from 'components/common/FormSelect';
import PurpleButton from './PurpleButton';
import { PermissionTypeValues } from 'store/views/addSessionView';

const Styled = {
Wrapper: styled.div``,
Expand Down Expand Up @@ -50,6 +51,14 @@ const AddSession: React.FC<Props> = ({ primary }) => {
);
}

const validatePermissionType = (v: string) => {
const permissionType = Object.values(PermissionTypeValues).find(value => value === v);

if (!permissionType) return;

addSessionView.setPermissionType(permissionType);
};

return (
<Wrapper>
<Row>
Expand All @@ -74,18 +83,18 @@ const AddSession: React.FC<Props> = ({ primary }) => {
<FormField>
<FormSelect
value={addSessionView.permissionType}
onChange={addSessionView.setPermissionType}
onChange={validatePermissionType}
options={[
{ label: l('admin'), value: 'admin' },
{ label: l('readonly'), value: 'read-only' },
{ label: l('custom'), value: 'custom' },
{ label: l('admin'), value: PermissionTypeValues.Admin },
{ label: l('readonly'), value: PermissionTypeValues.ReadOnly },
{ label: l('custom'), value: PermissionTypeValues.Custom },
]}
/>
</FormField>
</Column>
<Column>
<PurpleButton onClick={addSessionView.handleSubmit}>
{addSessionView.permissionType === 'custom'
{addSessionView.permissionType === PermissionTypeValues.Custom
? l('common.next')
: l('common.submit')}
</PurpleButton>
Expand Down
55 changes: 41 additions & 14 deletions app/src/components/connect/CustomSessionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import FormSelect from 'components/common/FormSelect';
import FormDate from 'components/common/FormDate';
import FormSwitch from 'components/common/v2/FormSwitch';
import PurpleButton from './PurpleButton';
import { PermissionTypeValues } from 'store/views/addSessionView';

const Styled = {
Wrapper: styled.div`
Expand Down Expand Up @@ -108,7 +109,7 @@ const CustomSessionPage: React.FC = () => {
addSessionView.handleCustomSubmit();
}, []);

const setPermissionType = (permissionType: string) => {
const setPermissionType = (permissionType: PermissionTypeValues) => {
return () => {
addSessionView.setPermissionType(permissionType);
};
Expand Down Expand Up @@ -175,48 +176,62 @@ const CustomSessionPage: React.FC = () => {

<PermissionTypes>
<PermissionType
active={addSessionView.permissionType === 'admin'}
onClick={setPermissionType('admin')}
active={addSessionView.permissionType === PermissionTypeValues.Admin}
onClick={setPermissionType(PermissionTypeValues.Admin)}
>
<Paragraph bold>{l('admin')}</Paragraph>
<Small>{l('adminDesc')}</Small>
</PermissionType>

<PermissionType
active={addSessionView.permissionType === 'read-only'}
onClick={setPermissionType('read-only')}
active={addSessionView.permissionType === PermissionTypeValues.ReadOnly}
onClick={setPermissionType(PermissionTypeValues.ReadOnly)}
>
<Paragraph bold>{l('readonly')}</Paragraph>
<Small>{l('readonlyDesc')}</Small>
</PermissionType>

<PermissionType
active={addSessionView.permissionType === 'liquidity'}
onClick={setPermissionType('liquidity')}
active={
addSessionView.permissionType === PermissionTypeValues.Liquidity
}
onClick={setPermissionType(PermissionTypeValues.Liquidity)}
>
<Paragraph bold>{l('liquidity')}</Paragraph>
<Small>{l('liquidityDesc')}</Small>
</PermissionType>

<PermissionType
active={addSessionView.permissionType === 'payments'}
onClick={setPermissionType('payments')}
active={addSessionView.permissionType === PermissionTypeValues.Payments}
onClick={setPermissionType(PermissionTypeValues.Payments)}
>
<Paragraph bold>{l('payments')}</Paragraph>
<Small>{l('paymentsDesc')}</Small>
</PermissionType>

<PermissionType
active={addSessionView.permissionType === 'custodial'}
onClick={setPermissionType('custodial')}
active={
addSessionView.permissionType === PermissionTypeValues.Messenger
}
onClick={setPermissionType(PermissionTypeValues.Messenger)}
>
<Paragraph bold>{l('messenger')}</Paragraph>
<Small>{l('messengerDesc')}</Small>
</PermissionType>

<PermissionType
active={
addSessionView.permissionType === PermissionTypeValues.Custodial
}
onClick={setPermissionType(PermissionTypeValues.Custodial)}
>
<Paragraph bold>{l('custodial')}</Paragraph>
<Small>{l('custodialDesc')}</Small>
</PermissionType>

<PermissionType
active={addSessionView.permissionType === 'custom'}
onClick={setPermissionType('custom')}
active={addSessionView.permissionType === PermissionTypeValues.Custom}
onClick={setPermissionType(PermissionTypeValues.Custom)}
>
<Paragraph bold>{l('custom')}</Paragraph>
<Small>{l('customDesc')}</Small>
Expand All @@ -228,7 +243,7 @@ const CustomSessionPage: React.FC = () => {
<Label semiBold>Permissions</Label>

<Permissions>
{addSessionView.permissionType === 'custodial' && (
{addSessionView.permissionType === PermissionTypeValues.Custodial && (
<FormField>
<Label semiBold space={8}>
{l('addBalance')}
Expand Down Expand Up @@ -335,6 +350,18 @@ const CustomSessionPage: React.FC = () => {
onChange={togglePermission('receive')}
/>
</Permission>

<Permission>
<div>
<Paragraph bold>{l('permSign')}</Paragraph>
<Small>{l('permSignDesc')}</Small>
</div>

<FormSwitch
checked={addSessionView.permissions.sign}
onChange={togglePermission('sign')}
/>
</Permission>
</Permissions>
</Column>
</Row>
Expand Down
4 changes: 4 additions & 0 deletions app/src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"cmps.connect.CustomSessionPage.liquidityDesc": "User can only set fees, use Loop, and use Pool.",
"cmps.connect.CustomSessionPage.payments": "Payments Manager",
"cmps.connect.CustomSessionPage.paymentsDesc": "User can only send and receive payments.",
"cmps.connect.CustomSessionPage.messenger": "Keysend Messenger",
"cmps.connect.CustomSessionPage.messengerDesc": "User can send and receive payments plus sign messages.",
"cmps.connect.CustomSessionPage.custodial": "Custodial Account",
"cmps.connect.CustomSessionPage.custodialDesc": "Create a custodial off-chain account for your node.",
"cmps.connect.CustomSessionPage.custom": "Custom",
Expand All @@ -78,6 +80,8 @@
"cmps.connect.CustomSessionPage.permSendDesc": "Send funds from this node.",
"cmps.connect.CustomSessionPage.permReceive": "Receive",
"cmps.connect.CustomSessionPage.permReceiveDesc": "Receive funds on this node.",
"cmps.connect.CustomSessionPage.permSign": "Sign",
"cmps.connect.CustomSessionPage.permSignDesc": "Sign messages to verify node.",
"cmps.connect.CustomSessionPage.advanced": "Advanced Options",
"cmps.connect.CustomSessionPage.proxy": "Proxy Server",
"cmps.connect.CustomSessionPage.proxyDesc": "Specify a custom Lightning Node Connect proxy server",
Expand Down
48 changes: 33 additions & 15 deletions app/src/store/views/addSessionView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import { Store } from 'store';
import * as LIT from 'types/generated/lit-sessions_pb';
import { MAX_DATE, PermissionUriMap } from 'util/constants';

export enum PermissionTypeValues {
Admin = 'admin',
ReadOnly = 'read-only',
Liquidity = 'liquidity',
Payments = 'payments',
Messenger = 'messenger',
Custodial = 'custodial',
Custom = 'custom',
}

export default class AddSessionView {
private _store: Store;

label = '';
permissionType = 'admin'; // Expected values: admin | read-only | custodial | custom | liquidity | payments
permissionType: PermissionTypeValues = PermissionTypeValues.Admin;
editing = false;
permissions: { [key: string]: boolean } = {
openChannel: false,
Expand All @@ -17,6 +27,7 @@ export default class AddSessionView {
pool: false,
send: false,
receive: false,
sign: false,
};
expiration = 'never'; // Expected values: 7 | 30 | 60 | 90 | never | custom
expirationOptions = [
Expand Down Expand Up @@ -49,11 +60,11 @@ export default class AddSessionView {
//

get sessionType() {
if (this.permissionType === 'admin') {
if (this.permissionType === PermissionTypeValues.Admin) {
return LIT.SessionType.TYPE_MACAROON_ADMIN;
} else if (this.permissionType === 'read-only') {
} else if (this.permissionType === PermissionTypeValues.ReadOnly) {
return LIT.SessionType.TYPE_MACAROON_READONLY;
} else if (this.permissionType === 'custodial') {
} else if (this.permissionType === PermissionTypeValues.Custodial) {
return LIT.SessionType.TYPE_MACAROON_ACCOUNT;
}

Expand Down Expand Up @@ -132,45 +143,52 @@ export default class AddSessionView {
this.custodialBalance = balance;
}

setPermissionType(permissionType: string) {
setPermissionType(permissionType: PermissionTypeValues) {
this.permissionType = permissionType;

switch (permissionType) {
case 'admin':
case PermissionTypeValues.Admin:
this.setAllPermissions(true);
break;

case 'read-only':
case PermissionTypeValues.ReadOnly:
this.setAllPermissions(false);
break;

case 'liquidity':
case PermissionTypeValues.Liquidity:
this.setAllPermissions(false);
this.permissions.setFees = true;
this.permissions.loop = true;
this.permissions.pool = true;
break;

case 'payments':
case PermissionTypeValues.Payments:
this.setAllPermissions(false);
this.permissions.send = true;
this.permissions.receive = true;
break;

case PermissionTypeValues.Messenger:
this.setAllPermissions(false);
this.permissions.send = true;
this.permissions.receive = true;
this.permissions.sign = true;
break;

case 'custodial':
case PermissionTypeValues.Custodial:
this.setAllPermissions(false);
this.permissions.send = true;
this.permissions.receive = true;
break;

case 'custom':
case PermissionTypeValues.Custom:
// We don't need to change anything, let the user customize permissions how they want
break;
}
}

togglePermission(permission: string) {
this.setPermissionType('custom');
this.setPermissionType(PermissionTypeValues.Custom);
this.permissions[permission] = !this.permissions[permission];
}

Expand All @@ -184,7 +202,7 @@ export default class AddSessionView {

cancel() {
this.label = '';
this.permissionType = 'admin';
this.permissionType = PermissionTypeValues.Admin;
this.editing = false;
this.setAllPermissions(false);
this.expiration = 'never';
Expand All @@ -197,7 +215,7 @@ export default class AddSessionView {
//

async handleSubmit() {
if (this.permissionType === 'custom') {
if (this.permissionType === PermissionTypeValues.Custom) {
this._store.settingsStore.sidebarVisible = false;
this._store.router.push('/connect/custom');
} else {
Expand All @@ -223,7 +241,7 @@ export default class AddSessionView {
label = `My ${this.permissionType} session`;
}

if (this.permissionType === 'custodial') {
if (this.permissionType === PermissionTypeValues.Custodial) {
const custodialAccountId = await this.registerCustodialAccount();

// Return immediately to prevent a session being created when there is an error creating the custodial account
Expand Down
1 change: 1 addition & 0 deletions app/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ export const PermissionUriMap: { [key: string]: string[] } = {
'/lnrpc.Lightning/ListInvoices',
'/lnrpc.Lightning/SubscribeInvoices',
],
sign: ['/lnrpc.Lightning/SignMessage'],
};