-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
- Loading branch information
Showing
19 changed files
with
1,242 additions
and
98 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 |
---|---|---|
@@ -1,44 +1,5 @@ | ||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
# Ledger BTC Wallet - React | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `yarn start` | ||
|
||
Runs the app in the development mode.<br /> | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
The page will reload if you make edits.<br /> | ||
You will also see any lint errors in the console. | ||
|
||
### `yarn test` | ||
|
||
Launches the test runner in the interactive watch mode.<br /> | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `yarn build` | ||
|
||
Builds the app for production to the `build` folder.<br /> | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.<br /> | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `yarn eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). | ||
```bash | ||
HTTPS=true yarn start | ||
``` |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} |
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 |
---|---|---|
@@ -1,26 +1,187 @@ | ||
import React from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
import React, { Component } from "react"; | ||
import { BitcoinApi, satToBtc } from "./bitcoin"; | ||
import * as ledger from "./ledger"; | ||
import { | ||
Container, | ||
Row, | ||
Col, | ||
Table, | ||
Button, | ||
Spinner, | ||
Jumbotron, | ||
} from "react-bootstrap"; | ||
import "./App.css"; | ||
import Wizard from "./Wizard"; | ||
|
||
const ENTRIES_PER_PAGE = 3; | ||
|
||
interface State { | ||
appBtc?: ledger.AppBtc; | ||
apiBtc: BitcoinApi; | ||
ready: boolean; | ||
loaded: boolean; | ||
accIndex: number; | ||
accounts: Record<string, { index: number; value: number }>; | ||
showModal: boolean; | ||
btcAddress: string; | ||
btcIndex: number; | ||
} | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(() => resolve(), ms)); | ||
} | ||
|
||
export default App; | ||
export default class App extends Component<{}, State> { | ||
state: State = { | ||
apiBtc: new BitcoinApi(), | ||
ready: false, | ||
loaded: false, | ||
accIndex: 0, | ||
accounts: {}, | ||
showModal: false, | ||
btcAddress: "", | ||
btcIndex: 0, | ||
}; | ||
|
||
async componentDidMount() { | ||
while (true) { | ||
try { | ||
const app = await ledger.connect(); | ||
await ledger.getWalletAddress(app, 0); | ||
this.setState({ appBtc: app, ready: true }); | ||
break; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
await sleep(1000); | ||
} | ||
|
||
if (this.state.ready) { | ||
await this.loadAccounts(ENTRIES_PER_PAGE); | ||
} | ||
} | ||
|
||
async loadAccounts(length: number) { | ||
const index = this.state.accIndex; | ||
let promises = []; | ||
for (let i = index; i < index + length; i++) { | ||
const addr = await ledger.getWalletAddress(this.state.appBtc!, i); | ||
const accounts = this.state.accounts; | ||
accounts[addr] = { index: i, value: 0 }; | ||
|
||
promises.push( | ||
this.state.apiBtc.getAccountValue(addr).then((value) => { | ||
const accounts = this.state.accounts; | ||
accounts[addr].value = value; | ||
this.setState({ | ||
accounts: accounts, | ||
}); | ||
}) | ||
); | ||
|
||
this.setState({ | ||
accounts: accounts, | ||
}); | ||
} | ||
await Promise.all(promises); | ||
this.setState({ | ||
loaded: true, | ||
accIndex: index + length, | ||
}); | ||
} | ||
|
||
async showModal(addr: string, index: number) { | ||
this.setState({ | ||
btcAddress: addr, | ||
btcIndex: index, | ||
showModal: true, | ||
}); | ||
} | ||
|
||
exitModal() { | ||
this.setState({ showModal: false }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="App"> | ||
<Container> | ||
{!this.state.ready && ( | ||
<div> | ||
<Jumbotron> | ||
<h1 className="header">Connect Your Device</h1> | ||
<p>You may need to open the Bitcoin app.</p> | ||
</Jumbotron> | ||
<Spinner | ||
as="span" | ||
animation="border" | ||
role="status" | ||
aria-hidden="true" | ||
/> | ||
</div> | ||
)} | ||
|
||
{this.state.ready && ( | ||
<div> | ||
<Jumbotron> | ||
<h1 className="header">Select An Address</h1> | ||
</Jumbotron> | ||
|
||
<Row className="justify-content-md-center"> | ||
<Col> | ||
<Table striped bordered hover> | ||
<thead> | ||
<tr> | ||
<th>Address</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{Object.keys(this.state.accounts).map((addr) => { | ||
return ( | ||
<tr | ||
key={addr} | ||
onClick={() => | ||
this.showModal( | ||
addr, | ||
this.state.accounts[addr].index | ||
) | ||
} | ||
> | ||
<td>{addr}</td> | ||
<td> | ||
{satToBtc(this.state.accounts[addr].value)} BTC | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</Table> | ||
</Col> | ||
</Row> | ||
<Row className="justify-content-md-center"> | ||
{this.state.loaded && ( | ||
<Button | ||
onClick={() => { | ||
this.setState({ loaded: false }); | ||
this.loadAccounts(ENTRIES_PER_PAGE); | ||
}} | ||
> | ||
Show More | ||
</Button> | ||
)} | ||
</Row> | ||
</div> | ||
)} | ||
</Container> | ||
{this.state.showModal && this.state.appBtc && ( | ||
<Wizard | ||
exitModal={this.exitModal.bind(this)} | ||
appBtc={this.state.appBtc} | ||
{...this.state} | ||
></Wizard> | ||
)} | ||
</div> | ||
); | ||
} | ||
} |
Oops, something went wrong.