Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 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
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 * as React from 'react'; | ||
import { Alert } from 'react-native' | ||
import { Container, Content, Form, Item, Input, Label, Button, Text, Spinner } from 'native-base'; | ||
import { styles as s } from "react-native-style-tachyons"; | ||
|
||
import { Transaction } from '../Types' | ||
|
||
interface Props { | ||
send: (amount: string) => Promise<Transaction> | ||
} | ||
|
||
interface State { | ||
amount: string | ||
sending: boolean | ||
} | ||
|
||
class TransferForm extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props) | ||
|
||
this.state = { | ||
amount: '', | ||
sending: false | ||
} | ||
} | ||
|
||
async send(): Promise<Transaction> { | ||
const { amount } = this.state | ||
|
||
this.setState({ | ||
sending: true | ||
}) | ||
|
||
const transaction = await this.props.send(amount) | ||
|
||
this.setState({ | ||
sending: false | ||
}) | ||
|
||
return transaction | ||
} | ||
|
||
render() { | ||
const { amount, sending } = this.state | ||
|
||
return ( | ||
<Container> | ||
<Content scrollEnabled={false}> | ||
<Form> | ||
<Item floatingLabel> | ||
<Label>Amount</Label> | ||
<Input | ||
onChangeText={(amount) => this.setState({ amount })} | ||
value={amount} | ||
keyboardType={'decimal-pad'} | ||
autoFocus={true} | ||
autoCorrect={false} | ||
autoCapitalize={"none"} | ||
/> | ||
</Item> | ||
{!sending && ( | ||
<Button full style={[s.mt4]} onPress={() => this.send()}> | ||
<Text>Send</Text> | ||
</Button> | ||
)} | ||
{sending && <Spinner color="blue" />} | ||
</Form> | ||
</Content> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
export default TransferForm |
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,30 @@ | ||
import * as React from 'react'; | ||
import { Alert } from 'react-native'; | ||
import TransferForm from '../../../app/components/TransferForm'; | ||
|
||
class TransferFormStory extends React.Component { | ||
render() { | ||
const transaction = { | ||
id: '1234' | ||
} | ||
|
||
const send = (amount: string) => { | ||
return new Promise((resolve) => { | ||
Alert.alert( | ||
`Sending ${amount} to or from your bank!`, | ||
'This should call the mutation deposit or withdrawal', | ||
[ | ||
{text: 'OK', onPress: () => resolve(transaction)}, | ||
], | ||
{ cancelable: false } | ||
) | ||
}) | ||
} | ||
|
||
return ( | ||
<TransferForm send={send} /> | ||
) | ||
} | ||
} | ||
|
||
export default TransferFormStory |
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