From 32744a45352ed94fcecb35a1f8e42bcf31f6f4bd Mon Sep 17 00:00:00 2001 From: bkioshn Date: Thu, 9 Mar 2023 21:44:14 +0700 Subject: [PATCH 1/2] fix: sort json attach funds --- src/lib/utils/funds.ts | 16 +++++++++------- src/lib/utils/getAttachFunds.ts | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/utils/funds.ts b/src/lib/utils/funds.ts index 8179d6c64..909652511 100644 --- a/src/lib/utils/funds.ts +++ b/src/lib/utils/funds.ts @@ -4,13 +4,15 @@ import type { Token } from "lib/types"; import { microfy } from "./formatter/currency"; +export const sortDenoms = (assets: Coin[]): Coin[] => + assets.sort(({ denom: aDenom }, { denom: bDenom }) => + aDenom.localeCompare(bDenom) + ); + export const fabricateFunds = (assets: Coin[]): Coin[] => - assets - .filter((asset) => Number(asset.amount) && asset.denom) - .sort(({ denom: aDenom }, { denom: bDenom }) => - aDenom.localeCompare(bDenom) - ) - .map((asset) => ({ + sortDenoms(assets.filter((asset) => Number(asset.amount) && asset.denom)).map( + (asset) => ({ ...asset, amount: microfy(asset.amount as Token).toFixed(0), - })); + }) + ); diff --git a/src/lib/utils/getAttachFunds.ts b/src/lib/utils/getAttachFunds.ts index 3579c5d43..8ca8f2fc3 100644 --- a/src/lib/utils/getAttachFunds.ts +++ b/src/lib/utils/getAttachFunds.ts @@ -2,7 +2,7 @@ import type { Coin } from "@cosmjs/stargate"; import { AttachFundsType } from "lib/components/fund/types"; -import { fabricateFunds } from "./funds"; +import { fabricateFunds, sortDenoms } from "./funds"; interface AttachFundsParams { attachFundsOption: AttachFundsType; @@ -21,7 +21,7 @@ export const getAttachFunds = ({ case AttachFundsType.ATTACH_FUNDS_JSON: try { if (JSON.parse(assetsJsonStr)) { - return JSON.parse(assetsJsonStr) as Coin[]; + return sortDenoms(JSON.parse(assetsJsonStr) as Coin[]); } } catch { return []; From d6b4e434e01587895c35bca609da32297a6428dc Mon Sep 17 00:00:00 2001 From: bkioshn Date: Thu, 9 Mar 2023 21:50:44 +0700 Subject: [PATCH 2/2] chore: add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 007569913..cf5ef68b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +- [#236](https://github.com/alleslabs/celatone-frontend/pull/236) Add alphabetically sorting to JSON attach funds - [#231](https://github.com/alleslabs/celatone-frontend/pull/231) Fix double slash for endpoint, disable calling endpoint when there is no contract addr in contract details page - [#229](https://github.com/alleslabs/celatone-frontend/pull/229) Disable Sentry debug to prevent "logger.info is not a function" error - [#219](https://github.com/alleslabs/celatone-frontend/pull/219) Fix asset value and price formatter