Skip to content

Commit

Permalink
Merge pull request #236 from alleslabs/fix/funds-sort
Browse files Browse the repository at this point in the history
fix: sort json attach funds
  • Loading branch information
bkioshn authored Mar 10, 2023
2 parents c852953 + d6b4e43 commit 09f110e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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

2 comments on commit 09f110e

@vercel
Copy link

@vercel vercel bot commented on 09f110e Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 09f110e Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.