Skip to content

Commit

Permalink
馃挷fix: Align currencies in the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hanania committed Apr 2, 2023
1 parent 82e071f commit fcfde50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ out/

# production
build
.idea

# misc
.DS_Store
Expand Down
9 changes: 4 additions & 5 deletions components/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Badges from "./json/badges/index.json";
import Tippy from "@tippyjs/react";
import moment from "moment";
import emojis from "./json/demo/emojis.json";
import currencies from "./json/other/currencies.json";
import Utils from "./utils";
import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";
Expand Down Expand Up @@ -11572,8 +11571,7 @@ export default function Data({ data, demo }: any): ReactElement {
</Tippy>
{data?.dataFile ? "They've " : "You've "}spent{" "}
<p className="mx-1 font-extrabold text-blue-500 inline-flex">
{Utils.getMostUsedCurrency(data.payments.transactions)}
{data?.payments?.total?.toFixed(2) || 0}
{Utils.getMostUsedCurrency(data.payments.transactions, data?.payments?.total?.toFixed(2) ?? 0)}
</p>
on Discord
</span>
Expand All @@ -11596,9 +11594,10 @@ export default function Data({ data, demo }: any): ReactElement {
<div className="inline-flex">
<p className="mx-1 font-extrabold inline-flex">
{Utils.getMostUsedCurrency(
data.payments.transactions
data.payments.transactions,
t?.amount ? t.amount : 0
)}
{t?.amount ? t.amount : 0}

</p>
on
<Tippy
Expand Down
15 changes: 10 additions & 5 deletions components/json/other/currencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
{
"currency": "Egypt Pound",
"abbreviation": "EGP",
"symbol": ""
"symbol": "",
"right": true
},
{
"currency": "El Salvador Colon",
Expand All @@ -172,7 +173,8 @@
{
"currency": "Falkland Islands (Malvinas) Pound",
"abbreviation": "FKP",
"symbol": ""
"symbol": "",
"right": true
},
{
"currency": "Fiji Dollar",
Expand All @@ -187,7 +189,8 @@
{
"currency": "Gibraltar Pound",
"abbreviation": "GIP",
"symbol": ""
"symbol": "",
"right": true
},
{
"currency": "Guatemala Quetzal",
Expand Down Expand Up @@ -432,7 +435,8 @@
{
"currency": "Saint Helena Pound",
"abbreviation": "SHP",
"symbol": ""
"symbol": "",
"right": true
},
{
"currency": "Saudi Arabia Riyal",
Expand Down Expand Up @@ -537,7 +541,8 @@
{
"currency": "United Kingdom Pound",
"abbreviation": "GBP",
"symbol": ""
"symbol": "",
"right": true
},
{
"currency": "United States Dollar",
Expand Down
12 changes: 9 additions & 3 deletions components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import currencies from "../json/other/currencies.json";
import connectionsJSON from "../json/connections.json";

class Utils {
static getMostUsedCurrency(transactions) {
static getMostUsedCurrency(transactions, amount) {
if (transactions == null) {
return;
}
Expand All @@ -34,8 +34,13 @@ class Utils {
(a) => a?.abbreviation.toLowerCase() === mostUsedCurrency
);

return currency.symbol;
// {amount}{symbol}
if (currency.right) return `${amount}${currency.symbol}`;

// {symbol}{amount}
else return `${currency.symbol}${amount}`;
}

static readFile(name, files) {
return new Promise((resolve) => {
const file = files.find((file) => {
Expand Down Expand Up @@ -445,7 +450,8 @@ class Utils {
.sort((a, b) => b.count - a.count);

const connectionsPossible = Object.keys(connectionsJSON);
const connectionsRand = Math.floor(Math.random() * connectionsPossible.length) + 1;
const connectionsRand =
Math.floor(Math.random() * connectionsPossible.length) + 1;
const connectionsArray = [];
for (let i = 0; i < connectionsRand; i++) {
const connectionsArray_ =
Expand Down

0 comments on commit fcfde50

Please sign in to comment.