Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort json attach funds #236

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/lib/utils/funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}));
})
);
4 changes: 2 additions & 2 deletions src/lib/utils/getAttachFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [];
Expand Down