-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): Mobile Trade: improve Buy section stub coin inter…
…actions
- Loading branch information
Showing
7 changed files
with
209 additions
and
25 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
26 changes: 26 additions & 0 deletions
26
suite-native/module-trading/src/components/buy/ReceiveAccountCryptoBalance.tsx
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,26 @@ | ||
import { useFormatters } from '@suite-common/formatters'; | ||
import { NetworkSymbol } from '@suite-common/wallet-config'; | ||
import { Box, Text } from '@suite-native/atoms'; | ||
|
||
export type ReceiveAccountBalanceProps = { | ||
symbol: NetworkSymbol | undefined; | ||
balance: string | undefined; | ||
}; | ||
|
||
export const RECEIVE_ACCOUNT_BALANCE_TEST_ID = '@module-trading/receive-account-balance'; | ||
|
||
export const ReceiveAccountCryptoBalance = ({ symbol, balance }: ReceiveAccountBalanceProps) => { | ||
const { CryptoAmountFormatter } = useFormatters(); | ||
|
||
const shouldDisplayBalance = symbol && balance; | ||
|
||
return ( | ||
<Box testID={RECEIVE_ACCOUNT_BALANCE_TEST_ID}> | ||
{shouldDisplayBalance && ( | ||
<Text variant="body" color="textSubdued"> | ||
<CryptoAmountFormatter value={balance} symbol={symbol} /> | ||
</Text> | ||
)} | ||
</Box> | ||
); | ||
}; |
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
32 changes: 32 additions & 0 deletions
32
...ive/module-trading/src/components/buy/__tests__/ReceiveAccountCryptoBalance.comp.test.tsx
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,32 @@ | ||
import { render } from '@suite-native/test-utils'; | ||
|
||
import { | ||
RECEIVE_ACCOUNT_BALANCE_TEST_ID, | ||
ReceiveAccountCryptoBalance, | ||
} from '../ReceiveAccountCryptoBalance'; | ||
|
||
describe('ReceiveAccountBalance', () => { | ||
it('should display empty box when symbol is not specified', () => { | ||
const { getByTestId } = render( | ||
<ReceiveAccountCryptoBalance symbol={undefined} balance="10000" />, | ||
); | ||
|
||
expect(getByTestId(RECEIVE_ACCOUNT_BALANCE_TEST_ID)).toHaveTextContent(''); | ||
}); | ||
|
||
it('should display empty box when balance is not specified', () => { | ||
const { getByTestId } = render( | ||
<ReceiveAccountCryptoBalance symbol="btc" balance={undefined} />, | ||
); | ||
|
||
expect(getByTestId(RECEIVE_ACCOUNT_BALANCE_TEST_ID)).toHaveTextContent(''); | ||
}); | ||
|
||
it('should display balance when symbol and balance is specified', () => { | ||
const { getByTestId } = render( | ||
<ReceiveAccountCryptoBalance symbol="btc" balance="1000000" />, | ||
); | ||
|
||
expect(getByTestId(RECEIVE_ACCOUNT_BALANCE_TEST_ID)).toHaveTextContent('0.01 BTC'); | ||
}); | ||
}); |
88 changes: 88 additions & 0 deletions
88
suite-native/module-trading/src/components/buy/__tests__/ReceiveAccountPicker.comp.test.tsx
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,88 @@ | ||
import { Account } from '@suite-common/wallet-types'; | ||
import { fireEvent, render } from '@suite-native/test-utils'; | ||
import { Address } from '@trezor/blockchain-link-types'; | ||
|
||
import { ReceiveAccountPicker, ReceiveAccountPickerProps } from '../ReceiveAccountPicker'; | ||
|
||
jest.mock('../../general/AccountSheet/AccountSheet'); | ||
|
||
describe('ReceiveAccountPicker', () => { | ||
const renderPicker = ({ | ||
selectedSymbol, | ||
selectedValue, | ||
setSelectedValue = jest.fn(), | ||
isSheetVisible = false, | ||
hideSheet = jest.fn(), | ||
showSheet = jest.fn(), | ||
}: Partial<ReceiveAccountPickerProps>) => | ||
render( | ||
<ReceiveAccountPicker | ||
selectedSymbol={selectedSymbol} | ||
isSheetVisible={isSheetVisible} | ||
hideSheet={hideSheet} | ||
showSheet={showSheet} | ||
setSelectedValue={setSelectedValue} | ||
selectedValue={selectedValue} | ||
/>, | ||
); | ||
|
||
it('should display "Select coin first" when selectedSymbol is not specified', () => { | ||
const { getByText } = renderPicker({ selectedSymbol: undefined }); | ||
|
||
expect(getByText('Select coin first')).toBeDefined(); | ||
}); | ||
|
||
it('should not call showSheet when selectedSymbol is not specified', () => { | ||
const showSheet = jest.fn(); | ||
const { getByText } = renderPicker({ selectedSymbol: undefined, showSheet }); | ||
|
||
fireEvent.press(getByText('Receive account')); | ||
|
||
expect(showSheet).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should display "Not selected" when selectedValue is not specified', () => { | ||
const { getByText } = renderPicker({ selectedSymbol: 'btc', selectedValue: undefined }); | ||
|
||
expect(getByText('Not selected')).toBeDefined(); | ||
}); | ||
|
||
it('should call showSheet when selectedSymbol is specified and picker pressed', () => { | ||
const showSheet = jest.fn(); | ||
const { getByText } = renderPicker({ selectedSymbol: 'btc', showSheet }); | ||
|
||
fireEvent.press(getByText('Receive account')); | ||
|
||
expect(showSheet).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should display selected account name', () => { | ||
const { getByText } = renderPicker({ | ||
selectedSymbol: 'eth', | ||
selectedValue: { | ||
account: { | ||
accountLabel: 'Account label', | ||
} as unknown as Account, | ||
}, | ||
}); | ||
|
||
expect(getByText('Account label')).toBeDefined(); | ||
}); | ||
|
||
it('should display selected account name and address', () => { | ||
const { getByText } = renderPicker({ | ||
selectedSymbol: 'btc', | ||
selectedValue: { | ||
account: { | ||
accountLabel: 'Account label', | ||
} as unknown as Account, | ||
address: { | ||
address: 'Address', | ||
} as unknown as Address, | ||
}, | ||
}); | ||
|
||
expect(getByText('Account label')).toBeDefined(); | ||
expect(getByText('Address')).toBeDefined(); | ||
}); | ||
}); |
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