-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(suite): style add contact modal
- Loading branch information
Showing
4 changed files
with
186 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { Column, Input, NewModal, Textarea } from '@trezor/components'; | ||
import { selectDevice } from '@suite-common/wallet-core'; | ||
import { spacings } from '@trezor/theme'; | ||
|
||
import { useSelector } from '../../hooks/suite'; | ||
import { getDeviceState } from '../../reducers/suite/contactsReducer'; | ||
import { useAddContact } from './useAddContact'; | ||
|
||
type AddNewContactModalProps = { | ||
onClose: () => void; | ||
}; | ||
|
||
export const AddNewContactModal = ({ onClose }: AddNewContactModalProps) => { | ||
const device = useSelector(selectDevice); | ||
const deviceState = device && getDeviceState(device); | ||
|
||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
const [label, setLabel] = useState(''); | ||
const [address, setAddress] = useState(''); | ||
|
||
const addContact = useAddContact(onClose, label, address); | ||
const onAddContact = async () => { | ||
const { error } = await addContact(); | ||
setErrorMessage(error); | ||
}; | ||
|
||
if (!deviceState || errorMessage) | ||
return ( | ||
<NewModal | ||
onCancel={onClose} | ||
iconName="warningFilled" | ||
variant="warning" | ||
size="small" | ||
bottomContent={ | ||
<NewModal.Button variant="tertiary" onClick={onClose}> | ||
Close | ||
</NewModal.Button> | ||
} | ||
> | ||
No device selected or device unacquired | ||
</NewModal> | ||
); | ||
|
||
return ( | ||
<NewModal | ||
heading="Add new contact" | ||
onCancel={onClose} | ||
size="medium" | ||
bottomContent={ | ||
<> | ||
<NewModal.Button onClick={onAddContact}>Save</NewModal.Button> | ||
<NewModal.Button variant="tertiary" onClick={onClose}> | ||
Cancel | ||
</NewModal.Button> | ||
</> | ||
} | ||
> | ||
<Column gap={spacings.sm}> | ||
<Input | ||
value={label} | ||
label="Label for this recipient" | ||
onChange={event => setLabel(event.target.value)} | ||
/> | ||
<Textarea | ||
value={address} | ||
label="Recipient's address or public key" | ||
onChange={event => setAddress(event.target.value)} | ||
/> | ||
</Column> | ||
</NewModal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Button, Card, Dropdown, Table, Text } from '@trezor/components'; | ||
import { spacings } from '@trezor/theme'; | ||
|
||
import { Contact } from '../../types/suite'; | ||
|
||
const ContactItem = ({ | ||
contact: { address, label, signature }, | ||
remove, | ||
}: { | ||
contact: Contact; | ||
remove: () => void; | ||
}) => { | ||
return ( | ||
<Table.Row> | ||
<Table.Cell> | ||
<Text typographyStyle="highlight">{label}</Text> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<Text variant="tertiary" typographyStyle="hint" overflowWrap="anywhere"> | ||
{address} | ||
</Text> | ||
</Table.Cell> | ||
<Table.Cell> | ||
<Text variant="tertiary" typographyStyle="hint" overflowWrap="anywhere"> | ||
{signature} | ||
</Text> | ||
</Table.Cell> | ||
<Table.Cell align="right"> | ||
<Dropdown | ||
alignMenu="bottom-right" | ||
items={[ | ||
{ | ||
key: '1', | ||
label: 'Contact', | ||
options: [ | ||
{ | ||
label: 'Delete', | ||
icon: 'userMinusFilled', | ||
onClick: remove, | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
); | ||
}; | ||
|
||
export const ContactList = ({ | ||
contacts, | ||
remove, | ||
onAdd, | ||
}: { | ||
contacts: Contact[]; | ||
remove: (contact: Contact) => void; | ||
onAdd: () => void; | ||
}) => { | ||
return ( | ||
<Card paddingType="none" overflow="hidden"> | ||
<Table isRowHighlightedOnHover margin={{ top: spacings.xs }}> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.Cell>Label</Table.Cell> | ||
<Table.Cell>Address</Table.Cell> | ||
<Table.Cell>Signature</Table.Cell> | ||
<Table.Cell /> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{contacts.map((contact, i) => ( | ||
<ContactItem key={i} contact={contact} remove={() => remove(contact)} /> | ||
))} | ||
</Table.Body> | ||
<Table.Footer> | ||
<Table.Row hasBorderTop={true} isHighlightedOnHover={false}> | ||
<Table.Cell colSpan={4}> | ||
<Button onClick={onAdd} size="small" icon="plus"> | ||
Add new contact | ||
</Button> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table.Footer> | ||
</Table> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters