Skip to content

Commit

Permalink
Restore default selection logic (#3393)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding authored Jul 28, 2020
1 parent 228a641 commit 2a31758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/AccountDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import { formatEther } from 'ethers/utils';
import { OptionProps } from 'react-select';
import isEmpty from 'lodash/isEmpty';

import { translateRaw } from '@translations';
import { AccountSummary, Divider, Selector } from '@components';
import { SPACING } from '@theme';
import { StoreAccount, Asset, TUuid, TSymbol } from '@types';
import { getAccountBalance, getBaseAsset } from '@services/Store';
import { useEffectOnce } from '@vendor';

export interface IAccountDropdownProps {
accounts: StoreAccount[];
Expand Down Expand Up @@ -51,6 +53,12 @@ function AccountDropdown({ accounts, asset, name, value, onSelect }: IAccountDro
const selected = getOption(value, options);
const handleFormUpdate = (option: TAccountDropdownOption) => onSelect(option.account);

useEffectOnce(() => {
if (!isEmpty(options) && isEmpty(value)) {
onSelect(options[0].account);
}
});

return (
<Selector<TAccountDropdownOption>
name={name}
Expand Down
8 changes: 8 additions & 0 deletions src/components/AssetSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import styled from 'styled-components';
import { OptionProps } from 'react-select';
import isEmpty from 'lodash/isEmpty';

import { translateRaw } from '@translations';
import { Asset, ISwapAsset, TSymbol, TUuid } from '@types';
import { AssetIcon, Typography, Selector } from '@components';
import { useEffectOnce } from '@vendor';

const SContainer = styled('div')`
display: flex;
Expand Down Expand Up @@ -79,6 +81,12 @@ function AssetSelector({
inputId = 'asset-selector',
...props
}: AssetSelectorProps<Asset | ISwapAsset>) {
useEffectOnce(() => {
if (!isEmpty(assets) && isEmpty(selectedAsset)) {
onSelect(assets[0]);
}
});

return (
<Wrapper fluid={fluid}>
{label && <Label htmlFor={inputId}>{label}</Label>}
Expand Down

0 comments on commit 2a31758

Please sign in to comment.