Skip to content

Commit

Permalink
clean up names
Browse files Browse the repository at this point in the history
  • Loading branch information
marslavish committed Dec 20, 2023
1 parent 24aa0b8 commit f3c8fe8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ or get the `ChainInfo` object:
const chainInfo: ChainInfo = registry.getChainInfo('osmosis');

// AssetList[] of the generated assets
const assetes: AssetList[] = chainInfo.assetLists;
const assets: AssetList[] = chainInfo.assetLists;

// Chain
const chain: Chain = chainInfo.chain;

// AssetList[] of the native assets
const assetes: AssetList[] = chainInfo.nativeAssetLists;
// Native asset list
const nativeAssetList: AssetList = chainInfo.nativeAssetList;
```

## Related
Expand Down
2 changes: 1 addition & 1 deletion packages/client/__tests__/client-mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ describe('Test client', () => {

it('Test mock fetching asset list', () => {
const chainInfo = client.getChainInfo('osmosis');
expect(chainInfo.nativeAssetLists.assets.length).toEqual(1);
expect(chainInfo.nativeAssetList.assets.length).toEqual(1);
});
});
2 changes: 1 addition & 1 deletion packages/client/__tests__/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Test fetcher', () => {
expect(chainInfo.chain).toEqual(osmosis);

const osmosisAssets = fetcher.getChainAssetList('osmosis');
expect(chainInfo.nativeAssetLists).toEqual(osmosisAssets);
expect(chainInfo.nativeAssetList).toEqual(osmosisAssets);

const num = osmosisAssets.assets.length;
const numGenerated = generated[0].assets.length;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/chain-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ChainInfo {
get chain() {
return this._chain;
}
get nativeAssetLists() {
get nativeAssetList() {
return this._assetList;
}
get assetLists() {
Expand Down
27 changes: 14 additions & 13 deletions packages/client/src/chain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ export interface ChainRegistryChainUtilOptions {
export class ChainRegistryChainUtil {
chainName: string;
chainInfo: ChainInfo;
allAsset: AssetList[];

private _assets: AssetList[] = [];

constructor(options: ChainRegistryChainUtilOptions) {
this.chainName = options.chainName;
this.chainInfo = options.chainInfo;
this.allAsset = [
this._assets = [
{
assets: [
...this.chainInfo.nativeAssetLists.assets,
...this.chainInfo.nativeAssetList.assets,
...this.chainInfo.assetLists.flatMap(({ assets }) => assets)
],
chain_name: this.chainName
Expand All @@ -46,35 +47,35 @@ export class ChainRegistryChainUtil {
}

getAssetByDenom(denom: CoinDenom): Asset {
return getAssetByDenom(this.allAsset, denom, this.chainName);
return getAssetByDenom(this._assets, denom, this.chainName);
}

getDenomByCoinGeckoId(coinGeckoId: string): CoinDenom {
return getDenomByCoinGeckoId(this.allAsset, coinGeckoId, this.chainName);
return getDenomByCoinGeckoId(this._assets, coinGeckoId, this.chainName);
}

getCoinGeckoIdByDenom(coinGeckoId: string): CoinDenom {
return getCoinGeckoIdByDenom(this.allAsset, coinGeckoId, {
return getCoinGeckoIdByDenom(this._assets, coinGeckoId, {
chainName: this.chainName
});
}

getSymbolByChainDenom(denom: CoinDenom): string {
return getSymbolByChainDenom(this.allAsset, denom, this.chainName);
return getSymbolByChainDenom(this._assets, denom, this.chainName);
}

getChainDenomBySymbol(token: string): CoinDenom {
return getChainDenomBySymbol(this.allAsset, token, this.chainName);
return getChainDenomBySymbol(this._assets, token, this.chainName);
}

getExponentByDenom(denom: CoinDenom): Exponent {
return getExponentByDenom(this.allAsset, denom, this.chainName);
return getExponentByDenom(this._assets, denom, this.chainName);
}

convertCoinGeckoPricesToDenomPriceMap(
prices: Record<string, CoinGeckoUSD>
): PriceHash {
return convertCoinGeckoPricesToDenomPriceMap(this.allAsset, prices);
return convertCoinGeckoPricesToDenomPriceMap(this._assets, prices);
}

noDecimals(num: number | string): string {
Expand All @@ -87,7 +88,7 @@ export class ChainRegistryChainUtil {
amount: string | number
): string {
return convertBaseUnitsToDollarValue(
this.allAsset,
this._assets,
prices,
symbol,
amount,
Expand All @@ -101,7 +102,7 @@ export class ChainRegistryChainUtil {
value: string | number
): string {
return convertDollarValueToDenomUnits(
this.allAsset,
this._assets,
prices,
symbol,
value,
Expand All @@ -114,7 +115,7 @@ export class ChainRegistryChainUtil {
amount: string | number
): string {
return convertBaseUnitsToDisplayUnits(
this.allAsset,
this._assets,
symbol,
amount,
this.chainName
Expand Down

0 comments on commit f3c8fe8

Please sign in to comment.