Skip to content
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

Make fiat conversions accurate #770

Merged
merged 4 commits into from
Jul 26, 2023
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
1 change: 1 addition & 0 deletions .changelog/770.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make fiat conversions accurate
4 changes: 2 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js 18
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
uses: actions/[email protected]
with:
python-version: '3.x'
- name: Set up Node.js 18
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js 18
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cloudflare-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
# Checkout pull request HEAD commit instead of merge commit.
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Node.js 18
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/generate-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ jobs:
working-directory: src/oasis-nexus
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
node-version: '20.x'
cache: yarn
cache-dependency-path: src/oasis-nexus/yarn.lock
- run: yarn install --frozen-lockfile
- run: yarn generate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js 18
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"last 1 safari version"
]
},
"engines": {
"node": ">=19"
},
"resolutions": {
"**/@emotion/styled": "11.11.0",
"@typescript-eslint/eslint-plugin": "6.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TokenPriceInfo } from '../../../coin-gecko/api'
import { ContractCreatorInfo } from './ContractCreatorInfo'
import { ContractVerificationIcon } from '../ContractVerificationIcon'
import { TokenLink } from '../Tokens/TokenLink'
import BigNumber from 'bignumber.js'

export const StyledAvatarContainer = styled('dt')(({ theme }) => ({
'&&': {
Expand Down Expand Up @@ -154,7 +155,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
<dd>
<FiatMoneyAmountBox>
{t('common.fiatValueInUSD', {
value: parseFloat(balance) * tokenFiatValue,
value: new BigNumber(balance).multipliedBy(tokenFiatValue).toFixed(),
formatParams: {
value: {
currency: 'USD',
Expand Down
5 changes: 3 additions & 2 deletions src/app/pages/TransactionDetailPage/CurrentFiatValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import Tooltip from '@mui/material/Tooltip'
import { CoinGeckoReferral } from '../../components/CoinGeckoReferral'
import HelpIcon from '@mui/icons-material/Help'
import { TokenPriceInfo } from '../../../coin-gecko/api'
import BigNumber from 'bignumber.js'

type CurrentFiatValueProps = Pick<TokenPriceInfo, 'price' | 'hasUsedCoinGecko'> & {
amount: number
amount: string
}

export const CurrentFiatValue: FC<CurrentFiatValueProps> = ({ amount, price, hasUsedCoinGecko }) => {
Expand All @@ -17,7 +18,7 @@ export const CurrentFiatValue: FC<CurrentFiatValueProps> = ({ amount, price, has
<FiatMoneyAmountBox>
<Box sx={{ display: 'inline-flex', alignItems: 'center' }}>
{t('common.fiatValueInUSD', {
value: amount * price,
value: new BigNumber(amount).multipliedBy(price).toFixed(),
formatParams: {
value: {
currency: 'USD',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { screen, render } from '@testing-library/react'
import { CurrentFiatValue } from '../CurrentFiatValue'

describe('CurrentFiatValue', () => {
it('should display formatted values', () => {
render(
<CurrentFiatValue
hasUsedCoinGecko={true}
amount="1000000000100000000010000000001000000000.10000000001"
price={0.55555}
/>,
)
expect(screen.getByText('$555,550,000,055,555,000,005,555,500,000,555,550,000.06')).toBeInTheDocument()
expect(screen.getByText('CoinGecko')).toBeInTheDocument()
})
})
2 changes: 1 addition & 1 deletion src/app/pages/TransactionDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const TransactionDetailView: FC<{
<>
<dt>{t('currentFiatValue.title')}</dt>
<dd>
<CurrentFiatValue amount={parseFloat(transaction.amount)} {...tokenPriceInfo} />
<CurrentFiatValue amount={transaction.amount} {...tokenPriceInfo} />
</dd>
</>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/locales/__tests__/i18n-formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('formatting fiat currency with i18n', () => {
const { result } = renderHook(() => {
const { t } = useTranslation()
return t('does_not_exist.use_default', '{{value, currency}}', {
value: 123.456789,
value: '111222333444555666777888999.111222333444555666',
formatParams: {
value: {
currency: 'USD',
Expand All @@ -38,7 +38,7 @@ test('formatting fiat currency with i18n', () => {
}) as string
})

expect(result.current).toBe('$123.46')
expect(result.current).toBe('$111,222,333,444,555,666,777,888,999.11')
lukaw3d marked this conversation as resolved.
Show resolved Hide resolved
})

test('formatting block sizes with i18n', () => {
Expand Down