-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from etclabscore/feat/add-list-account-caveats
feat: add list account caveats
- Loading branch information
Showing
9 changed files
with
151 additions
and
11 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,24 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import AccountSelectList from "./AccountSelectList"; | ||
|
||
describe("AccountSelectList", () => { | ||
it("can render without crashing", () => { | ||
const div = document.createElement("div"); | ||
ReactDOM.render(<AccountSelectList accounts={[]}/>, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); | ||
it("can render accounts", () => { | ||
const div = document.createElement("div"); | ||
ReactDOM.render(<AccountSelectList accounts={[ | ||
{ | ||
address: "0x123", | ||
name: "potato", | ||
hidden: false, | ||
}, | ||
]}/>, div); | ||
expect(div.innerHTML).toContain("0x123"); | ||
expect(div.innerHTML).toContain("potato"); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); | ||
}); |
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,51 @@ | ||
import React, { useState } from "react"; | ||
import { List, ListItem, ListItemText, ListItemSecondaryAction, Checkbox, Typography } from "@material-ui/core"; | ||
import { Account } from "@etclabscore/signatory-core"; | ||
|
||
interface IProps { | ||
accounts: Account[]; | ||
onChange?: (checked: Account[]) => void; | ||
} | ||
|
||
const AccountSelectList: React.FC<IProps> = (props) => { | ||
const [checked, setChecked] = useState<Account[]>([]); | ||
|
||
const handleToggle = (value: Account) => () => { | ||
const currentIndex = checked.indexOf(value); | ||
const newChecked = [...checked]; | ||
|
||
if (currentIndex === -1) { | ||
newChecked.push(value); | ||
} else { | ||
newChecked.splice(currentIndex, 1); | ||
} | ||
|
||
setChecked(newChecked); | ||
if (props.onChange) { | ||
props.onChange(newChecked); | ||
} | ||
}; | ||
return ( | ||
<List> | ||
{props.accounts.map((account) => { | ||
return ( | ||
<ListItem onClick={handleToggle(account)} button> | ||
<ListItemText primary={ | ||
<Typography variant="caption" style={{ fontSize: "9px" }}> | ||
{account.address} | ||
</Typography> | ||
} secondary={account.name}></ListItemText> | ||
<ListItemSecondaryAction> | ||
<Checkbox | ||
onChange={handleToggle(account)} | ||
checked={checked.indexOf(account) !== -1} | ||
/> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
); | ||
})} | ||
</List> | ||
); | ||
}; | ||
|
||
export default AccountSelectList; |
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
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
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
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