New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new payment form component. #18

Merged
merged 1 commit into from Jul 23, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+453 −0
Diff settings

Always

Just for now

Copy path View file
@@ -0,0 +1,88 @@
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: (username: string, amount: string) => Promise<Transaction>
didSend: () => void
}

interface State {
amount: string
username: string
sending: boolean
}

class PaymentForm extends React.Component<Props, State> {
constructor(props: Props) {
super(props)

this.state = {
amount: '',
username: '',
sending: false
}
}

async send(): Promise<Transaction> {
const { username, amount } = this.state

this.setState({
sending: true
})

const transaction = await this.props.send(username, amount)

this.setState({
sending: false
})

this.props.didSend()

return transaction
}

render() {
const { amount, username, sending } = this.state

return (
<Container style={{backgroundColor: '#F5FCFF'}}>
<Content scrollEnabled={false}>
<Form>
<Item floatingLabel>
<Label>Recipient username</Label>
<Input
onChangeText={(username) => this.setState({ username })}
value={username}
autoFocus={true}
autoCorrect={false}
autoCapitalize={"none"}
/>
</Item>
<Item floatingLabel>
<Label>Amount</Label>
<Input
onChangeText={(amount) => this.setState({ amount })}
value={amount}
keyboardType={'decimal-pad'}
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 PaymentForm
@@ -0,0 +1,18 @@
import * as React from 'react'
import PaymentForm from '../PaymentForm'

import * as renderer from 'react-test-renderer'

const send = (amount: string) => {
return new Promise.resolve({
id: '1234'
})
}

jest.useFakeTimers()

it('renders correctly', () => {
const rendered = renderer.create(<PaymentForm send={send} />).toJSON()

expect(rendered).toMatchSnapshot()
});
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.