Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
further fixes to null values
Browse files Browse the repository at this point in the history
  • Loading branch information
librehat committed Jun 7, 2020
1 parent b3d7e94 commit 8c06e26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
26 changes: 13 additions & 13 deletions plasmoid/contents/code/yahoofinance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { httpRequestP } from "httprequest.mjs";
function getRawValText(val, decimals) {
const result = val ? val.raw : null;
if (typeof result !== "number") {
return null;
return "N/A";
}
if (typeof decimals === "number") {
return result.toFixed(decimals);
Expand Down Expand Up @@ -108,18 +108,18 @@ export function resolveQuote(symbol) {
longName: priceResult.longName || priceResult.shortName,
instrument: priceResult.quoteType,
exchange: priceResult.exchange,
exchangeName: priceResult.exchangeName ? priceResult.exchangeName : null,
currentPrice: priceResult.regularMarketPrice ? priceResult.regularMarketPrice.raw.toFixed(decimals) : null,
dayHighPrice: priceResult.regularMarketDayHigh ? priceResult.regularMarketDayHigh.raw.toFixed(decimals) : null,
dayLowPrice: priceResult.regularMarketDayHigh ? priceResult.regularMarketDayLow.raw.toFixed(decimals) : null,
openPrice: priceResult.regularMarketOpen ? priceResult.regularMarketOpen.raw.toFixed(decimals) : null,
volume: priceResult.regularMarketVolume ? priceResult.regularMarketVolume.raw : null,
exchangeName: priceResult.exchangeName,
currentPrice: getRawValText(priceResult.regularMarketPrice, decimals),
dayHighPrice: getRawValText(priceResult.regularMarketDayHigh, decimals),
dayLowPrice: getRawValText(priceResult.regularMarketDayHigh, decimals),
openPrice: getRawValText(priceResult.regularMarketOpen, decimals),
volume: getRawValText(priceResult.regularMarketVolume),
updatedDateTime: new Date(priceResult.regularMarketTime * 1000),
priceChange: priceResult.regularMarketChange ? priceResult.regularMarketChange.raw.toFixed(decimals) : null,
priceChangePercentage: priceResult.regularMarketChangePercent ? (priceResult.regularMarketChangePercent.raw * 100).toFixed(2) : null,
priceChange: getRawValText(priceResult.regularMarketChange, decimals),
priceChangePercentage: priceResult.regularMarketChangePercent ? (priceResult.regularMarketChangePercent.raw * 100).toFixed(2) : "N/A",
priceDecimals: decimals,
previousClose: priceResult.regularMarketPreviousClose ? priceResult.regularMarketPreviousClose.raw.toFixed(decimals) : null,
marketCap: priceResult.marketCap ? priceResult.marketCap.raw : null,
previousClose: getRawValText(priceResult.regularMarketPreviousClose, decimals),
marketCap: getRawValText(priceResult.marketCap),
};
});
}
Expand Down Expand Up @@ -174,9 +174,9 @@ export function resolveProfile(symbol) {
components = result.components.components; // this could be null (e.g. ^SPX)
} else { // summaryProfile for non-index only
const profileResult = result.summaryProfile;
const address2 = profileResult.address2 ? profileResult.address2 + ", " : "";
const addresses = [profileResult.address1, profileResult.address2, profileResult.city, profileResult.zip, profileResult.country].filter(a => !!a);
summaryProfile = {
address: `${profileResult.address1}, ${address2}${profileResult.city} ${profileResult.zip}, ${profileResult.country}`,
address: addresses.join(", "),
phone: profileResult.phone,
website: profileResult.website,
industry: profileResult.industry,
Expand Down
7 changes: 4 additions & 3 deletions plasmoid/contents/ui/ProfilePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Item {
PlasmaExtras.Paragraph {
id: website
Layout.fillWidth: true
text: "N/A"
linkColor: theme.textColor
onLinkActivated: Qt.openUrlExternally(link)
}
Expand Down Expand Up @@ -259,9 +260,9 @@ Item {
if (summaryProfile.website) {
website.text = `<a href='${summaryProfile.website}'>${summaryProfile.website}</a>`;
}
sector.text = summaryProfile.sector;
industry.text = summaryProfile.industry;
description.text = summaryProfile.description;
sector.text = summaryProfile.sector ? summaryProfile.sector : "N/A";
industry.text = summaryProfile.industry ? summaryProfile.industry : "N/A";
description.text = summaryProfile.description ? summaryProfile.description : "N/A";
profileColumn.visible = true;
}

Expand Down
1 change: 1 addition & 0 deletions plasmoid/contents/ui/StockQuoteDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ PlasmaComponents.ListItem {
id: tooltip
anchors.fill: parent
mainText: `${shortName} (${symbol})`
// TODO: move this logic into `code`
subText: `Long Name: ${longName}
Type: ${instrument}
Exchange: ${exchange}
Expand Down

0 comments on commit 8c06e26

Please sign in to comment.