Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions app/components/UI/AccountInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ class AccountInput extends Component {
/**
* Network id
*/
updateToAddressError: PropTypes.func
updateToAddressError: PropTypes.func,
/**
* Callback to open accounts dropdown
*/
openAccountSelect: PropTypes.func,
/**
* Whether accounts dropdown is opened
*/
isOpen: PropTypes.bool
};

state = {
isOpen: false,
address: undefined,
ensRecipient: undefined,
value: undefined
Expand Down Expand Up @@ -204,9 +211,8 @@ class AccountInput extends Component {
};

onFocus = () => {
const { onFocus } = this.props;
const { isOpen } = this.state;
this.setState({ isOpen: !isOpen });
const { onFocus, isOpen, openAccountSelect } = this.props;
openAccountSelect && openAccountSelect(!isOpen);
onFocus && onFocus();
};

Expand Down Expand Up @@ -271,22 +277,25 @@ class AccountInput extends Component {
}

onChange = async value => {
const { accounts, onChange } = this.props;
const { accounts, onChange, openAccountSelect } = this.props;
const addresses = Object.keys(accounts).filter(address => address.toLowerCase().match(value.toLowerCase()));
const visibleOptions = value.length === 0 ? accounts : addresses.map(address => accounts[address]);
const match = visibleOptions.length === 1 && visibleOptions[0].address.toLowerCase() === value.toLowerCase();
this.setState({
isOpen: (value.length === 0 || visibleOptions.length) > 0 && !match,
value
});
openAccountSelect && openAccountSelect((value.length === 0 || visibleOptions.length) > 0 && !match);
onChange && onChange(value);
};

onInputFocus = () => {
this.setState({ isOpen: false });
const { openAccountSelect } = this.props;
openAccountSelect && openAccountSelect(true);
};

scan = () => {
const { openAccountSelect } = this.props;
openAccountSelect && openAccountSelect(false);
this.setState({ isOpen: false });
this.props.navigation.navigate('QRScanner', {
onScanSuccess: meta => {
Expand All @@ -298,8 +307,8 @@ class AccountInput extends Component {
};

render = () => {
const { isOpen, value, ensRecipient, address } = this.state;
const { placeholder } = this.props;
const { value, ensRecipient, address } = this.state;
const { placeholder, isOpen } = this.props;
return (
<View style={styles.root}>
<View style={styles.accountContainer}>
Expand Down
23 changes: 15 additions & 8 deletions app/components/UI/AccountSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,35 @@ class AccountSelect extends Component {
/**
* Address of the currently-selected account
*/
value: PropTypes.string
value: PropTypes.string,
/**
* Callback to open accounts dropdown
*/
openAccountSelect: PropTypes.func,
/**
* Whether accounts dropdown is opened
*/
isOpen: PropTypes.bool
};

static defaultProps = {
enabled: true
};

state = { isOpen: false };

componentDidMount() {
const { onChange, selectedAddress } = this.props;
onChange && onChange(selectedAddress);
}

renderActiveOption() {
const { selectedAddress, accounts, identities, value } = this.props;
const { selectedAddress, accounts, identities, value, isOpen, openAccountSelect } = this.props;
const targetAddress = toChecksumAddress(value || selectedAddress);
const account = { ...identities[targetAddress], ...accounts[targetAddress] };
return (
<View style={styles.activeOption}>
{this.props.enabled && <MaterialIcon name={'arrow-drop-down'} size={24} style={styles.arrow} />}
{this.renderOption(account, () => {
this.setState({ isOpen: !this.state.isOpen });
openAccountSelect && openAccountSelect(!isOpen);
})}
</View>
);
Expand Down Expand Up @@ -169,13 +175,14 @@ class AccountSelect extends Component {
}

renderOptionList() {
const { accounts, identities, onChange } = this.props;
const { accounts, identities, onChange, openAccountSelect } = this.props;
return (
<ScrollView style={styles.componentContainer}>
<View style={styles.optionList}>
{Object.keys(identities).map(address =>
this.renderOption({ ...identities[address], ...accounts[address] }, () => {
this.setState({ isOpen: false, value: address });
this.setState({ value: address });
openAccountSelect && openAccountSelect(true);
onChange && onChange(address);
})
)}
Expand All @@ -187,7 +194,7 @@ class AccountSelect extends Component {
render = () => (
<View style={styles.root}>
{this.renderActiveOption()}
{this.state.isOpen && this.props.enabled && this.renderOptionList()}
{this.props.isOpen && this.props.enabled && this.renderOptionList()}
</View>
);
}
Expand Down
10 changes: 9 additions & 1 deletion app/components/UI/ActionView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function ActionView({
confirmButtonMode,
onCancelPress,
onConfirmPress,
onTouchablePress,
showCancelButton,
showConfirmButton,
confirmed,
Expand All @@ -45,7 +46,9 @@ export default function ActionView({
return (
<View style={baseStyles.flexGrow}>
<KeyboardAwareScrollView style={baseStyles.flexGrow} resetScrollToCoords={{ x: 0, y: 0 }}>
<TouchableWithoutFeedback style={baseStyles.flexGrow}>{children}</TouchableWithoutFeedback>
<TouchableWithoutFeedback style={baseStyles.flexGrow} onPress={onTouchablePress}>
{children}
</TouchableWithoutFeedback>
</KeyboardAwareScrollView>
<View style={styles.actionContainer}>
{showCancelButton && (
Expand Down Expand Up @@ -127,6 +130,11 @@ ActionView.propTypes = {
* Called when the confirm button is clicked
*/
onConfirmPress: PropTypes.func,
/**
* Called when the touchable without feedback is clicked
*/
onTouchablePress: PropTypes.func,

/**
* Whether cancel button is shown
*/
Expand Down
18 changes: 13 additions & 5 deletions app/components/UI/CustomGas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ class CustomGas extends Component {
/**
* Object BN containing estimated gas limit
*/
gas: PropTypes.object
gas: PropTypes.object,
/**
* Callback to modify state in parent state
*/
onPress: PropTypes.func
};

state = {
Expand All @@ -129,7 +133,8 @@ class CustomGas extends Component {

onPressGasFast = () => {
const { fastGwei } = this.state;
const { gas } = this.props;
const { gas, onPress } = this.props;
onPress && onPress();
this.setState({
gasFastSelected: true,
gasAverageSelected: false,
Expand All @@ -142,7 +147,8 @@ class CustomGas extends Component {

onPressGasAverage = () => {
const { averageGwei } = this.state;
const { gas } = this.props;
const { gas, onPress } = this.props;
onPress && onPress();
this.setState({
gasFastSelected: false,
gasAverageSelected: true,
Expand All @@ -155,7 +161,8 @@ class CustomGas extends Component {

onPressGasSlow = () => {
const { safeLowGwei } = this.state;
const { gas } = this.props;
const { gas, onPress } = this.props;
onPress && onPress();
this.setState({
gasFastSelected: false,
gasAverageSelected: false,
Expand All @@ -168,7 +175,8 @@ class CustomGas extends Component {

onAdvancedOptions = () => {
const { advancedCustomGas, selected, fastGwei, averageGwei, safeLowGwei, customGasPrice } = this.state;
const { gas } = this.props;
const { gas, onPress } = this.props;
onPress && onPress();
if (advancedCustomGas) {
switch (selected) {
case 'slow':
Expand Down
23 changes: 16 additions & 7 deletions app/components/UI/EthInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,18 @@ class EthInput extends Component {
/**
* Transaction object associated with this transaction
*/
transaction: PropTypes.object
transaction: PropTypes.object,
/**
* Callback to open assets dropdown
*/
openEthInput: PropTypes.func,
/**
* Whether assets dropdown is opened
*/
isOpen: PropTypes.bool
};

state = { isOpen: false, readableValue: undefined, assets: undefined };
state = { readableValue: undefined, assets: undefined };

componentDidUpdate = () => {
const { fillMax, readableValue } = this.props;
Expand Down Expand Up @@ -231,13 +239,13 @@ class EthInput extends Component {
};

onFocus = () => {
const { isOpen } = this.state;
this.setState({ isOpen: !isOpen });
const { isOpen, openEthInput } = this.props;
openEthInput && openEthInput(!isOpen);
};

selectAsset = async asset => {
this.setState({ isOpen: false });
const { handleUpdateAsset, onChange } = this.props;
const { handleUpdateAsset, onChange, openEthInput } = this.props;
openEthInput && openEthInput(false);
handleUpdateAsset && (await handleUpdateAsset(asset));
onChange && onChange(undefined);
this.setState({ readableValue: undefined });
Expand Down Expand Up @@ -412,7 +420,8 @@ class EthInput extends Component {
};

render = () => {
const { isOpen, assets } = this.state;
const { assets } = this.state;
const { isOpen } = this.props;
const selectAssets = assets && assets.length > 1;
return (
<View style={styles.root}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`TransactionEdit should render correctly 1`] = `
confirmText="Next"
confirmed={false}
onConfirmPress={[Function]}
onTouchablePress={[Function]}
showCancelButton={true}
showConfirmButton={true}
>
Expand All @@ -25,6 +26,7 @@ exports[`TransactionEdit should render correctly 1`] = `
Object {
"flex": 1,
"flexDirection": "column",
"minHeight": "100%",
"padding": 16,
}
}
Expand Down Expand Up @@ -138,7 +140,9 @@ exports[`TransactionEdit should render correctly 1`] = `
</View>
<Connect(EthInput)
fillMax={false}
isOpen={false}
onChange={[Function]}
openEthInput={[Function]}
updateFillMax={[Function]}
value=""
/>
Expand Down Expand Up @@ -184,6 +188,7 @@ exports[`TransactionEdit should render correctly 1`] = `
</View>
<Connect(AccountInput)
address="0x2"
isOpen={false}
navigation={
Object {
"state": Object {
Expand All @@ -194,6 +199,7 @@ exports[`TransactionEdit should render correctly 1`] = `
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
openAccountSelect={[Function]}
placeholder="Recipient Address"
updateToAddressError={[Function]}
/>
Expand Down Expand Up @@ -241,6 +247,7 @@ exports[`TransactionEdit should render correctly 1`] = `
gas=""
gasPrice=""
handleGasFeeSelection={[Function]}
onPress={[Function]}
totalGas={"14a"}
/>
</View>
Expand Down
Loading