Skip to content

Commit

Permalink
Merge pull request #226 from nautls/arobsn/i225
Browse files Browse the repository at this point in the history
Rank assets by known and sort alphabetically
  • Loading branch information
arobsn authored Dec 2, 2024
2 parents b72a6a3 + 216cfc1 commit d0073a6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@oruga-ui/oruga-next": "0.6.0",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^11.3.0",
"@vueuse/core": "^12.0.0",
"bignumber.js": "^9.1.2",
"cleave.js": "^1.6.0",
"crypto-js": "^4.2.0",
Expand All @@ -46,7 +46,7 @@
"ledger-ergo-js": "^0.1.19",
"lodash-es": "^4.17.21",
"mdi-vue": "^3.0.13",
"pinia": "^2.2.6",
"pinia": "^2.2.8",
"uqr": "^0.1.2",
"vue": "^3.5.13",
"vue-feather": "^2.0.0",
Expand Down
40 changes: 33 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions src/stores/walletStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { hdKeyPool } from "@/common/objectPool";
import HdKey, { IndexedAddress } from "@/chains/ergo/hdKey";
import { graphQLService } from "@/chains/ergo/services/graphQlService";
import { patchArray } from "@/common/reactivity";
import { assetIconMap } from "@/mappers/assetIconMap";

export type StateAssetSummary = {
tokenId: string;
Expand All @@ -35,6 +36,8 @@ export type StateAssetSummary = {
metadata?: BasicAssetMetadata;
};

const KNOWN_ASSETS = new Set(Object.keys(assetIconMap));

const usePrivateStateStore = defineStore("_wallet", () => {
const addresses = shallowRef<IDbAddress[]>([]);
const assets = shallowRef<IDbAsset[]>([]);
Expand Down Expand Up @@ -204,9 +207,24 @@ export const useWalletStore = defineStore("wallet", () => {
summary = summary.filter((x) => x.tokenId === ERG_TOKEN_ID || x.confirmedAmount.gt(0));
}

return summary.sort((a, b) =>
a.tokenId === ERG_TOKEN_ID ? Number.MIN_SAFE_INTEGER : a.tokenId.localeCompare(b.tokenId)
if (summary.length <= 1) return summary;

// sort alphabetically
summary = summary.sort((a, b) =>
a.metadata?.name && b.metadata?.name
? a.metadata.name.localeCompare(b.metadata.name)
: a.tokenId.localeCompare(b.tokenId)
);

// rank by known assets
summary = summary.sort((a, b) =>
KNOWN_ASSETS.has(a.tokenId) && !KNOWN_ASSETS.has(b.tokenId) ? -1 : 1
);

// put ERG first
summary = summary.sort((a) => (a.tokenId === ERG_TOKEN_ID ? -1 : 1));

return summary;
});

const health = computed(() => ({
Expand Down

0 comments on commit d0073a6

Please sign in to comment.