Skip to content

Commit

Permalink
feat: add alphabetical order for assets list
Browse files Browse the repository at this point in the history
  • Loading branch information
jplorek-atix committed Jan 19, 2021
1 parent 1f7047a commit 886d38c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion source/features/address/api/transformers.ts
Expand Up @@ -5,6 +5,7 @@ import {
SearchForStakeAddressQuery,
} from '../../../../generated/typings/graphql-schema';
import { IPaymentAddressSummary, IStakeAddressSummary } from '../types';
import { sortTokensAlphabetically } from '../../../lib/arrays';

export const paymentAddressDetailTransformer = (
address: string,
Expand All @@ -20,7 +21,8 @@ export const paymentAddressDetailTransformer = (
tokensBalance:
s
.paymentAddresses![0]?.summary?.assetBalances?.filter(isDefined)
.filter(({ assetName }) => assetName !== 'ada') || [],
.filter(({ assetName }) => assetName !== 'ada')
.sort(sortTokensAlphabetically) || [],
};
};

Expand Down
13 changes: 9 additions & 4 deletions source/features/transactions/api/transformers.ts
@@ -1,6 +1,7 @@
import { Currency } from 'cardano-js';
import { TransactionDetailsFragment } from '../../../../generated/typings/graphql-schema';
import { isDefined } from '../../../lib/types';
import { sortTokensAlphabetically } from '../../../lib/arrays';
import { ITransactionDetails } from '../types';

export const transactionDetailsTransformer = (
Expand All @@ -24,7 +25,8 @@ export const transactionDetailsTransformer = (
.map((t) => ({
...t,
assetName: t.assetName || '-',
})),
}))
.sort(sortTokensAlphabetically),
})),
metadata: tx.metadata?.filter(isDefined).map((i) => ({
key: i.key,
Expand All @@ -38,7 +40,8 @@ export const transactionDetailsTransformer = (
.map((t) => ({
...t,
assetName: t.assetName || '-',
})),
}))
.sort(sortTokensAlphabetically),
})),
totalOutput: Currency.Util.lovelacesToAda(tx.totalOutput),
withdrawals:
Expand All @@ -52,13 +55,15 @@ export const transactionDetailsTransformer = (
.map((i) => ({
...i,
assetName: i.assetName || '-',
})) || [],
}))
.sort(sortTokensAlphabetically) || [],
burn:
tx.mint
?.filter((m) => m.quantity < '0')
.map((i) => ({
...i,
quantity: i.quantity.substring(1),
assetName: i.assetName || '-',
})) || [],
}))
.sort(sortTokensAlphabetically) || [],
});
9 changes: 9 additions & 0 deletions source/lib/arrays.ts
Expand Up @@ -5,3 +5,12 @@ export function compareProp<Item, Prop>(pickFrom: (i: Item) => Prop) {
return valA === valB ? 0 : valA < valB ? 1 : -1;
};
}

export const sortTokensAlphabetically = (t1: any, t2: any) => {
const tokenName1 = t1.assetName.toUpperCase();
const tokenName2 = t2.assetName.toUpperCase();
const tokenName1IsLower = tokenName1 < tokenName2;
const tokenName1IsGreater = tokenName1 > tokenName2;

return tokenName1IsLower ? -1 : tokenName1IsGreater ? 1 : 0;
};

0 comments on commit 886d38c

Please sign in to comment.