-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1265 from oasisprotocol/csillag/special-ticker-fo…
…r-paratime Add support for using different tokens on ParaTimes
- Loading branch information
Showing
30 changed files
with
456 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for using different tokens on ParaTimes |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,51 @@ | ||
import { styled } from '@mui/material/styles' | ||
import WarningIcon from '@mui/icons-material/WarningAmber' | ||
import Box from '@mui/material/Box' | ||
import { useTranslation } from 'react-i18next' | ||
import { FC } from 'react' | ||
import { CoinGeckoReferral } from '../CoinGeckoReferral' | ||
import { FiatValueInfo } from './hooks' | ||
import Tooltip from '@mui/material/Tooltip' | ||
import Skeleton from '@mui/material/Skeleton' | ||
|
||
export const FiatMoneyAmountBox = styled(Box)(() => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
gap: 4, | ||
flex: 1, | ||
})) | ||
|
||
export const FiatMoneyAmount: FC<FiatValueInfo> = ({ | ||
value, | ||
fiatCurrency, | ||
hasUsedCoinGecko, | ||
unknownTickers, | ||
loading, | ||
}) => { | ||
const { t } = useTranslation() | ||
return ( | ||
<FiatMoneyAmountBox> | ||
<span> | ||
{t('common.fiatValueInUSD', { | ||
value, | ||
formatParams: { | ||
value: { | ||
currency: fiatCurrency, | ||
} satisfies Intl.NumberFormatOptions, | ||
}, | ||
})} | ||
{!!unknownTickers.length && ( | ||
<Tooltip | ||
title={t('account.failedToLookUpTickers', { tickers: unknownTickers.join(', ') })} | ||
placement="top" | ||
> | ||
<WarningIcon /> | ||
</Tooltip> | ||
)} | ||
{loading && <Skeleton variant="rectangular" sx={{ height: 200 }} />} | ||
</span> | ||
{hasUsedCoinGecko && <CoinGeckoReferral />} | ||
</FiatMoneyAmountBox> | ||
) | ||
} |
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,25 @@ | ||
import { FC } from 'react' | ||
import { RuntimeSdkBalance } from '../../../oasis-nexus/api' | ||
import { useTranslation } from 'react-i18next' | ||
import { getPreciseNumberFormat } from '../../../locales/getPreciseNumberFormat' | ||
|
||
export const RuntimeBalanceDisplay: FC<{ balances: RuntimeSdkBalance[] | undefined }> = ({ | ||
balances = [], | ||
}) => { | ||
const { t } = useTranslation() | ||
if (balances.length === 0 || balances[0].balance === undefined) { | ||
return t('common.missing') | ||
} | ||
return ( | ||
<> | ||
{balances.map(balance => ( | ||
<span key={balance.token_symbol}> | ||
{t('common.valueInToken', { | ||
...getPreciseNumberFormat(balance.balance), | ||
ticker: balance.token_symbol, | ||
})} | ||
</span> | ||
))} | ||
</> | ||
) | ||
} |
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,83 @@ | ||
import { RuntimeSdkBalance } from '../../../oasis-nexus/api' | ||
import { AllTokenPrices } from '../../../coin-gecko/api' | ||
import BigNumber from 'bignumber.js' | ||
import { Ticker } from '../../../types/ticker' | ||
|
||
export const hasRuntimeBalance = (balances: RuntimeSdkBalance[] = []) => | ||
balances.some(balance => balance.token_decimals) | ||
|
||
export type FiatValueInfo = { | ||
/** | ||
* Do we have any known real value? | ||
*/ | ||
hasValue: boolean | ||
|
||
/** | ||
* The fiat value, to the best of our information | ||
*/ | ||
value?: string | ||
|
||
/** | ||
* The fiat currency used to express the value | ||
*/ | ||
fiatCurrency: string | ||
|
||
/** | ||
* Have we used CoinGecko for calculating this value? | ||
*/ | ||
hasUsedCoinGecko: boolean | ||
|
||
/** | ||
* Is the value of one of the tokens still being loaded? | ||
*/ | ||
loading: boolean | ||
|
||
/** | ||
* Any tokens for which we don't know the value? | ||
*/ | ||
unknownTickers: Ticker[] | ||
} | ||
|
||
export const calculateFiatValue = ( | ||
balances: RuntimeSdkBalance[] = [], | ||
tokenPrices: AllTokenPrices, | ||
fiatCurrency: string, | ||
): FiatValueInfo => { | ||
let hasValue = false | ||
let value = new BigNumber(0) | ||
let hasUsedCoinGecko = false | ||
let loading = false | ||
const unknown: Ticker[] = [] | ||
|
||
balances.forEach(balance => { | ||
const priceInfo = tokenPrices[balance.token_symbol as Ticker] | ||
if (priceInfo) { | ||
if (priceInfo.isLoading) { | ||
loading = true | ||
} else { | ||
hasUsedCoinGecko = hasUsedCoinGecko || priceInfo.hasUsedCoinGecko | ||
if (!priceInfo.isFree) { | ||
const tokenFiatValue = priceInfo.price | ||
hasValue = true | ||
if (tokenFiatValue === undefined) { | ||
unknown.push(balance.token_symbol as Ticker) | ||
} else { | ||
value = value.plus(new BigNumber(balance.balance).multipliedBy(tokenFiatValue)) | ||
} | ||
} | ||
} | ||
} else { | ||
unknown.push(balance.token_symbol as Ticker) | ||
hasValue = true | ||
} | ||
}) | ||
|
||
return { | ||
hasValue, | ||
hasUsedCoinGecko, | ||
loading, | ||
unknownTickers: unknown, | ||
value: value.toFixed(), | ||
fiatCurrency, | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/app/components/logo/SmallLogo.tsx → src/app/components/logo/SmallOasisLogo.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { FC } from 'react' | ||
import logo from '../../../../public/logo512.png' | ||
|
||
export const SmallLogo: FC<{ size?: number }> = ({ size = 25 }) => ( | ||
export const SmallOasisLogo: FC<{ size?: number }> = ({ size = 25 }) => ( | ||
<img src={logo} height={size} width={size} alt="" /> | ||
) |
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,15 @@ | ||
import { FC } from 'react' | ||
import { Ticker } from '../../../types/ticker' | ||
import { SmallOasisLogo } from './SmallOasisLogo' | ||
import euroELogo from '../../../../public/euroe.png' | ||
|
||
export const SmallTokenLogo: FC<{ ticker: Ticker }> = ({ ticker }) => { | ||
switch (ticker) { | ||
case 'ROSE': | ||
return <SmallOasisLogo /> | ||
case 'EUROe': | ||
return <img src={euroELogo} width={25} alt={ticker} /> | ||
default: | ||
return null | ||
} | ||
} |
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
Oops, something went wrong.