Convert opensource CSVs to JSON (#273)
* 🧱 use json instead of csv
* Fixed code size in MessageDetailsDialog
This commit is contained in:
@@ -7,7 +7,6 @@ import type {
|
||||
PotentialMarketParsedCsv,
|
||||
} from '@/constants/potentialMarkets';
|
||||
|
||||
import csvToArray from '@/lib/csvToArray';
|
||||
import { log } from '@/lib/telemetry';
|
||||
|
||||
const PotentialMarketsContext = createContext<ReturnType<typeof usePotentialMarketsContext>>({
|
||||
@@ -24,8 +23,8 @@ export const PotentialMarketsProvider = ({ ...props }) => (
|
||||
|
||||
export const usePotentialMarkets = () => useContext(PotentialMarketsContext);
|
||||
|
||||
const EXCHANGE_CONFIG_FILE_PATH = '/configs/potentialMarketExchangeConfig.csv';
|
||||
const POTENTIAL_MARKETS_FILE_PATH = '/configs/potentialMarketParameters.csv';
|
||||
const EXCHANGE_CONFIG_FILE_PATH = '/configs/potentialMarketExchangeConfig.json';
|
||||
const POTENTIAL_MARKETS_FILE_PATH = '/configs/potentialMarketParameters.json';
|
||||
|
||||
export const usePotentialMarketsContext = () => {
|
||||
const [potentialMarkets, setPotentialMarkets] = useState<PotentialMarketItem[]>();
|
||||
@@ -34,50 +33,9 @@ export const usePotentialMarketsContext = () => {
|
||||
useEffect(() => {
|
||||
try {
|
||||
fetch(POTENTIAL_MARKETS_FILE_PATH)
|
||||
.then((response) => response.text())
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const parsedData = csvToArray<PotentialMarketParsedCsv>({
|
||||
stringVal: data,
|
||||
splitter: ',',
|
||||
});
|
||||
const parsedPotentialMarkets = parsedData.map(
|
||||
({
|
||||
base_asset,
|
||||
reference_price,
|
||||
num_oracles,
|
||||
liquidity_tier,
|
||||
asset_name,
|
||||
p,
|
||||
atomic_resolution,
|
||||
min_exchanges,
|
||||
min_price_change_ppm,
|
||||
price_exponent,
|
||||
step_base_quantum,
|
||||
ticksize_exponent,
|
||||
subticks_per_tick,
|
||||
min_order_size,
|
||||
quantum_conversion_exponent,
|
||||
}) => ({
|
||||
// convert to camelCase
|
||||
baseAsset: base_asset,
|
||||
referencePrice: reference_price,
|
||||
numOracles: Number(num_oracles),
|
||||
liquidityTier: Number(liquidity_tier),
|
||||
assetName: asset_name,
|
||||
p: Number(p),
|
||||
atomicResolution: Number(atomic_resolution),
|
||||
minExchanges: Number(min_exchanges),
|
||||
minPriceChangePpm: Number(min_price_change_ppm),
|
||||
priceExponent: Number(price_exponent),
|
||||
stepBaseQuantum: Number(step_base_quantum),
|
||||
ticksizeExponent: Number(ticksize_exponent),
|
||||
subticksPerTick: Number(subticks_per_tick),
|
||||
minOrderSize: Number(min_order_size),
|
||||
quantumConversionExponent: Number(quantum_conversion_exponent),
|
||||
})
|
||||
);
|
||||
|
||||
setPotentialMarkets(parsedPotentialMarkets);
|
||||
setPotentialMarkets(data as PotentialMarketItem[]);
|
||||
});
|
||||
} catch (error) {
|
||||
log('usePotentialMarkets/potentialMarkets', error);
|
||||
@@ -86,40 +44,9 @@ export const usePotentialMarketsContext = () => {
|
||||
|
||||
try {
|
||||
fetch(EXCHANGE_CONFIG_FILE_PATH)
|
||||
.then((response) => response.text())
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const parsedData = csvToArray<ExchangeConfigParsedCsv>({
|
||||
stringVal: data,
|
||||
splitter: ',',
|
||||
});
|
||||
// create an object with the base_asset as the key and the value as an array of exchanges
|
||||
const exchangeConfigMap = parsedData.reduce(
|
||||
(acc: Record<string, ExchangeConfigItem[]>, curr) => {
|
||||
const { base_asset, exchange, pair, adjust_by_market } = curr;
|
||||
if (!acc[base_asset]) {
|
||||
acc[base_asset] = [];
|
||||
}
|
||||
|
||||
const exchangeItem: {
|
||||
exchangeName: string;
|
||||
ticker: string;
|
||||
adjustByMarket?: string;
|
||||
} = {
|
||||
exchangeName: exchange,
|
||||
ticker: pair,
|
||||
};
|
||||
|
||||
if (adjust_by_market) {
|
||||
exchangeItem.adjustByMarket = adjust_by_market;
|
||||
}
|
||||
|
||||
acc[base_asset].push(exchangeItem);
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
setExchangeConfigs(exchangeConfigMap);
|
||||
setExchangeConfigs(data as Record<string, ExchangeConfigItem[]>);
|
||||
});
|
||||
} catch (error) {
|
||||
log('usePotentialMarkets/exchangeConfigs', error);
|
||||
|
||||
@@ -433,7 +433,6 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
params,
|
||||
utils.getGovAddNewMarketTitle(params.ticker),
|
||||
utils.getGovAddNewMarketSummary(params.ticker, newMarketProposal.delayBlocks),
|
||||
// @ts-ignore - Need to change type in v4-client-js
|
||||
BigInt(newMarketProposal.initialDepositAmount).toString()
|
||||
);
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
const csvToArray = <T>({ stringVal, splitter }: { stringVal: string; splitter: string }) => {
|
||||
const [keys, ...rest] = stringVal
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((item) => item.split(splitter));
|
||||
|
||||
const formedArr = rest.map((item) => {
|
||||
const object: Record<string, string> = {};
|
||||
keys.forEach((key, index) => (object[key] = item[index]));
|
||||
return object;
|
||||
});
|
||||
|
||||
return formedArr as T;
|
||||
};
|
||||
|
||||
export default csvToArray;
|
||||
@@ -128,7 +128,7 @@ export const NewMarketMessageDetailsDialog = ({
|
||||
{'['}
|
||||
{exchangeConfig?.map((exchange) => {
|
||||
return (
|
||||
<Styled.Code
|
||||
<Styled.ExchangeObject
|
||||
key={exchange.exchangeName}
|
||||
style={{ padding: 0, margin: 0, paddingLeft: '0.5rem' }}
|
||||
>
|
||||
@@ -139,7 +139,7 @@ export const NewMarketMessageDetailsDialog = ({
|
||||
</Styled.Line>
|
||||
))}
|
||||
{'},'}
|
||||
</Styled.Code>
|
||||
</Styled.ExchangeObject>
|
||||
);
|
||||
})}
|
||||
{']'}
|
||||
@@ -337,17 +337,22 @@ Styled.Text0 = styled.span`
|
||||
`;
|
||||
|
||||
Styled.Code = styled.div`
|
||||
height: 16.25rem;
|
||||
overflow: auto;
|
||||
display: block;
|
||||
background-color: var(--color-layer-1);
|
||||
padding: 1rem;
|
||||
border-radius: 10px;
|
||||
font: var(--font-mini-book);
|
||||
font-family: var(--fontFamily-monospace);
|
||||
margin-top: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0rem;
|
||||
`;
|
||||
|
||||
Styled.ExchangeObject = styled.div`
|
||||
padding: 1rem;
|
||||
`;
|
||||
|
||||
Styled.Details = styled(Details)`
|
||||
--details-item-height: 1.5rem;
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user