주식 매매 api 및 화면 오류 수정
This commit is contained in:
@@ -26,18 +26,46 @@ const getLatestBy = (items, key) => {
|
||||
};
|
||||
|
||||
const normalizeIndices = (data) => {
|
||||
if (!data || typeof data !== 'object' || Array.isArray(data)) return [];
|
||||
return Object.entries(data)
|
||||
.filter(([, value]) => value && typeof value === 'object')
|
||||
.map(([name, value]) => ({
|
||||
name,
|
||||
value: value?.value ?? '-',
|
||||
change: value?.change ?? '',
|
||||
percent: value?.percent ?? '',
|
||||
if (!data) return [];
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return data.map((item) => ({
|
||||
name: item?.name ?? '-',
|
||||
value: item?.value ?? '-',
|
||||
change: item?.change_value ?? item?.change ?? '',
|
||||
percent: item?.change_percent ?? item?.percent ?? '',
|
||||
direction: item?.direction ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
if (Array.isArray(data?.indices)) {
|
||||
return data.indices.map((item) => ({
|
||||
name: item?.name ?? '-',
|
||||
value: item?.value ?? '-',
|
||||
change: item?.change_value ?? item?.change ?? '',
|
||||
percent: item?.change_percent ?? item?.percent ?? '',
|
||||
direction: item?.direction ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
if (typeof data === 'object') {
|
||||
return Object.entries(data)
|
||||
.filter(([, value]) => value && typeof value === 'object')
|
||||
.map(([name, value]) => ({
|
||||
name,
|
||||
value: value?.value ?? '-',
|
||||
change: value?.change ?? '',
|
||||
percent: value?.percent ?? '',
|
||||
direction: value?.direction ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
const getDirection = (change, percent) => {
|
||||
const getDirection = (change, percent, direction) => {
|
||||
if (direction === 'red') return 'up';
|
||||
if (direction === 'blue') return 'down';
|
||||
const pick = (value) =>
|
||||
value === undefined || value === null || value === '' ? null : value;
|
||||
const raw = pick(change) ?? pick(percent);
|
||||
@@ -209,7 +237,8 @@ const Stock = () => {
|
||||
sortedIndices.map((item) => {
|
||||
const direction = getDirection(
|
||||
item.change,
|
||||
item.percent
|
||||
item.percent,
|
||||
item.direction
|
||||
);
|
||||
const changeText = [
|
||||
item.change,
|
||||
|
||||
Reference in New Issue
Block a user