Skip to content

Commit

Permalink
fix: code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Sep 19, 2024
1 parent e06f9f8 commit 956890c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions apps/namadillo/src/atoms/accounts/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getIntegration } from "@namada/integrations";
import { Account } from "@namada/types";
import { indexerApiAtom } from "atoms/api";
import { chainConfigAtom, nativeTokenAddressAtom } from "atoms/chain";
import { nativeTokenAddressAtom } from "atoms/chain";
import { shouldUpdateBalanceAtom } from "atoms/etc";
import { namadaExtensionConnectedAtom } from "atoms/settings";
import { queryDependentFn } from "atoms/utils";
import BigNumber from "bignumber.js";
import { atomWithMutation, atomWithQuery } from "jotai-tanstack-query";
import { chainConfigByName } from "registry";
import {
fetchAccountBalance,
fetchAccounts,
Expand Down Expand Up @@ -50,7 +51,7 @@ export const accountBalanceAtom = atomWithQuery<BigNumber>((get) => {
const tokenAddress = get(nativeTokenAddressAtom);
const enablePolling = get(shouldUpdateBalanceAtom);
const api = get(indexerApiAtom);
const chainConfig = get(chainConfigAtom("namada"));
const chainConfig = chainConfigByName("namada");

return {
// TODO: subscribe to indexer events when it's done
Expand Down
7 changes: 0 additions & 7 deletions apps/namadillo/src/atoms/chain/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
} from "atoms/settings";
import { queryDependentFn } from "atoms/utils";
import BigNumber from "bignumber.js";
import { atom } from "jotai";
import { atomWithQuery } from "jotai-tanstack-query";
import { atomFamily } from "jotai/utils";
import { ChainConfig, chainConfigByName } from "registry";
import { ChainParameters, ChainSettings } from "types";
import { calculateUnbondingPeriod } from "./functions";
import { fetchChainParameters, fetchRpcUrlFromIndexer } from "./services";
Expand Down Expand Up @@ -84,7 +81,3 @@ export const chainParametersAtom = atomWithQuery<ChainParameters>((get) => {
},
};
});

export const chainConfigAtom = atomFamily((chainName: string) =>
atom<ChainConfig>(() => chainConfigByName(chainName))
);
19 changes: 13 additions & 6 deletions apps/namadillo/src/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import namada from "./namada.json";

type MinimalDenom = string;
type ConfigName = string;
type ChainName = "cosmoshub" | "namada";
type ChainMinDenom = "uatom" | "namnam";

type Currency = {
coinDecimals: number;
Expand All @@ -20,15 +22,20 @@ const loadedConfigs: ChainConfig[] = [];
const minimalDenomMap: Map<string, number> = new Map();
const nameMap: Map<string, number> = new Map();

export function chainConfigByMinDenom(minDenom: string): ChainConfig {
// We assume that the map always has the key
const index = minimalDenomMap.get(minDenom)!;
export function chainConfigByMinDenom(minDenom: ChainMinDenom): ChainConfig {
const index = minimalDenomMap.get(minDenom);
if (!index) {
throw new Error("Chain config not found");
}

return loadedConfigs[index];
}

export function chainConfigByName(name: string): ChainConfig {
// We assume that the map always has the key
const index = nameMap.get(name)!;
export function chainConfigByName(name: ChainName): ChainConfig {
const index = nameMap.get(name);
if (!index) {
throw new Error("Chain config not found");
}
return loadedConfigs[index];
}

Expand Down

0 comments on commit 956890c

Please sign in to comment.