-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tomm/nft-gallery-0
- Loading branch information
Showing
8 changed files
with
216 additions
and
55 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
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,49 @@ | ||
import { render } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import CurrencyDisplay from 'src/components/CurrencyDisplay' | ||
import TokenDisplay from 'src/components/TokenDisplay' | ||
import { CryptoAmount, FiatAmount } from 'src/fiatExchanges/amount' | ||
import { CiCoCurrency } from 'src/utils/currencies' | ||
import { createMockStore } from 'test/utils' | ||
import { mockCusdAddress } from 'test/values' | ||
|
||
jest.mock('src/components/TokenDisplay') | ||
jest.mock('src/components/CurrencyDisplay') | ||
|
||
describe('CryptoAmount', () => { | ||
it('passes amount and token address to TokenDisplay', () => { | ||
render( | ||
<Provider store={createMockStore()}> | ||
<CryptoAmount amount={10} currency={CiCoCurrency.cUSD} testID="cryptoAmt" /> | ||
</Provider> | ||
) | ||
expect(TokenDisplay).toHaveBeenCalledWith( | ||
{ | ||
amount: 10, | ||
showLocalAmount: false, | ||
testID: 'cryptoAmt', | ||
tokenAddress: mockCusdAddress, | ||
}, | ||
{} | ||
) | ||
}) | ||
}) | ||
|
||
describe('FiatAmount', () => { | ||
it('passes amount and currency to CurrencyDisplay', () => { | ||
render(<FiatAmount amount={20} currency="USD" testID="fiatAmt" />) | ||
|
||
expect(CurrencyDisplay).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
amount: { | ||
value: 0, | ||
currencyCode: '', | ||
localAmount: { value: 20, currencyCode: 'USD', exchangeRate: 1 }, | ||
}, | ||
testID: 'fiatAmt', | ||
}), | ||
{} | ||
) | ||
}) | ||
}) |
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,50 @@ | ||
import BigNumber from 'bignumber.js' | ||
import React from 'react' | ||
import CurrencyDisplay, { FormatType } from 'src/components/CurrencyDisplay' | ||
import TokenDisplay from 'src/components/TokenDisplay' | ||
import { useTokenInfoBySymbol } from 'src/tokens/hooks' | ||
import { CiCoCurrency } from 'src/utils/currencies' | ||
|
||
export function CryptoAmount({ | ||
amount, | ||
currency, | ||
testID, | ||
}: { | ||
amount: BigNumber.Value | ||
currency: CiCoCurrency | ||
testID?: string | ||
}) { | ||
const { address } = useTokenInfoBySymbol(currency)! | ||
return ( | ||
<TokenDisplay amount={amount} tokenAddress={address} showLocalAmount={false} testID={testID} /> | ||
) | ||
} | ||
|
||
export function FiatAmount({ | ||
amount, | ||
currency, | ||
testID, | ||
formatType, | ||
}: { | ||
amount: BigNumber.Value | ||
currency: string | ||
testID?: string | ||
formatType?: FormatType | ||
}) { | ||
return ( | ||
<CurrencyDisplay | ||
amount={{ | ||
// The value and currencyCode here doesn't matter since the component will use `localAmount` | ||
value: 0, | ||
currencyCode: '', | ||
localAmount: { | ||
value: amount, | ||
currencyCode: currency, | ||
exchangeRate: 1, | ||
}, | ||
}} | ||
formatType={formatType} | ||
testID={testID} | ||
/> | ||
) | ||
} |
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
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