Skip to content

Commit

Permalink
Merge pull request #2269 from zeitgeistpm/decimal-error
Browse files Browse the repository at this point in the history
Fix decimal error on create market page
  • Loading branch information
robhyrk authored Mar 2, 2024
2 parents b7abe4f + 13d014b commit 78e52ab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions components/create/editor/Publishing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const Publishing = ({ editor, creationParams }: PublishingProps) => {
editor.form.moderation === "Permissionless" &&
editor.form.liquidity?.deploy &&
editor.form.currency === "ZTG"
? new Decimal(editor.form.liquidity.amount ?? 0).toNumber()
? new Decimal(editor.form.liquidity.amount || 0).toNumber()
: 0,
)
.plus(ztgTransactionFee ?? 0);
Expand All @@ -121,7 +121,7 @@ export const Publishing = ({ editor, creationParams }: PublishingProps) => {

const foreignCurrencyCost =
editor.form.liquidity?.deploy && editor.form.currency !== "ZTG"
? new Decimal(editor.form.liquidity.amount ?? 0)
? new Decimal(editor.form.liquidity.amount || 0)
.mul(2)
.plus(baseAssetTransactionFee ?? 0)
: null;
Expand Down Expand Up @@ -314,7 +314,7 @@ export const Publishing = ({ editor, creationParams }: PublishingProps) => {
</h4>
<div className="">
{new Decimal(
editor.form.liquidity.amount ?? 0,
editor.form.liquidity.amount || 0,
).toFixed(1)}{" "}
{editor.form.currency}
</div>
Expand Down
28 changes: 15 additions & 13 deletions components/front-page/HeroBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const HeroBanner = ({
bannerPlaceholder: string;
chainProperties: GenericChainProperties;
}) => {
const chartData = ztgHistory.prices.map(([timestamp, price]) => {
const chartData = ztgHistory.prices?.map(([timestamp, price]) => {
return { v: price, t: 1 };
});

const firstPrice = ztgHistory.prices[0][1];
const latestPrice = ztgHistory.prices[ztgHistory.prices.length - 1][1];
const firstPrice = ztgHistory.prices?.[0]?.[1];
const latestPrice = ztgHistory.prices?.[ztgHistory.prices.length - 1]?.[1];
const prctChange = ((latestPrice - firstPrice) / firstPrice) * 100;

return (
Expand Down Expand Up @@ -76,24 +76,26 @@ export const HeroBanner = ({
dot={false}
strokeWidth={2}
stroke={getColour(
chartData[0].v,
chartData[chartData.length - 1].v,
chartData?.[0].v,
chartData?.[chartData.length - 1].v,
)}
/>
<YAxis hide={true} domain={["dataMin", "dataMax"]} />
</LineChart>
</ResponsiveContainer>
</div>
<div className="flex flex-1 items-center justify-end gap-2">
<div>
<div className="text-md text-center font-semibold">
${latestPrice.toFixed(3)}
</div>
<div className="text-center text-sm">
{!isNaN(prctChange) ? prctChange.toFixed(1) : 0}%
{latestPrice && (
<div className="flex flex-1 items-center justify-end gap-2">
<div>
<div className="text-md text-center font-semibold">
${latestPrice.toFixed(3)}
</div>
<div className="text-center text-sm">
{!isNaN(prctChange) ? prctChange.toFixed(1) : 0}%
</div>
</div>
</div>
</div>
)}
</div>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/gql/historical-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getBaseAssetHistoricalPrices = async (): Promise<BasePrices> => {
const findPrice = (timestamp: number, prices: [number, number][]) => {
const date = new Date(Number(timestamp));

const price = prices.find((p) => {
const price = prices?.find((p) => {
return datesAreOnSameDay(date, new Date(p[0]));
});

Expand Down
2 changes: 1 addition & 1 deletion lib/state/market-creation/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export const useMarketDraftEditor = (): MarketDraftEditor => {
...draft.form,
liquidity: {
...draft.form.liquidity,
amount: draft.form.liquidity.amount ?? liquidity,
amount: draft.form.liquidity.amount || liquidity,
rows,
},
},
Expand Down

0 comments on commit 78e52ab

Please sign in to comment.