-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add static chains config (#1103)
* feat: add static chains config * fix: code review fixes
- Loading branch information
1 parent
2c1b5d5
commit dcb53aa
Showing
5 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"chainName": "Cosmos Hub", | ||
"currencies": [ | ||
{ | ||
"coinDecimals": 6, | ||
"coinDenom": "ATOM", | ||
"coinMinimalDenom": "uatom" | ||
} | ||
], | ||
"feeCurrencies": [ | ||
{ | ||
"coinDecimals": 6, | ||
"coinDenom": "ATOM", | ||
"coinMinimalDenom": "uatom" | ||
} | ||
], | ||
"stakeCurrency": { | ||
"coinDecimals": 6, | ||
"coinDenom": "ATOM", | ||
"coinMinimalDenom": "uatom" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import cosmoshub from "./cosmoshub.json"; | ||
import namada from "./namada.json"; | ||
|
||
type MinimalDenom = string; | ||
type ConfigName = string; | ||
type ChainName = "cosmoshub" | "namada"; | ||
type ChainMinDenom = "uatom" | "namnam"; | ||
|
||
type Currency = { | ||
coinDecimals: number; | ||
coinDenom: string; | ||
coinMinimalDenom: string; | ||
}; | ||
|
||
export type ChainConfig = { | ||
currencies: Currency[]; | ||
feeCurrencies: Currency[]; | ||
stakeCurrency: Currency; | ||
}; | ||
|
||
const loadedConfigs: ChainConfig[] = []; | ||
const minimalDenomMap: Map<string, number> = new Map(); | ||
const nameMap: Map<string, number> = new Map(); | ||
|
||
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: ChainName): ChainConfig { | ||
const index = nameMap.get(name); | ||
if (!index) { | ||
throw new Error("Chain config not found"); | ||
} | ||
return loadedConfigs[index]; | ||
} | ||
|
||
function loadConfigs(configs: [MinimalDenom, ConfigName, ChainConfig][]): void { | ||
configs.forEach(([minimalDenom, name, config], index) => { | ||
loadedConfigs.push(config); | ||
|
||
minimalDenomMap.set(minimalDenom, index); | ||
nameMap.set(name, index); | ||
}); | ||
} | ||
|
||
loadConfigs([ | ||
["namnam", "namada", namada], | ||
["uatom", "cosmoshub", cosmoshub], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"chainName": "Namada", | ||
"currencies": [ | ||
{ | ||
"coinDecimals": 6, | ||
"coinDenom": "NAM", | ||
"coinMinimalDenom": "namnam" | ||
} | ||
], | ||
"feeCurrencies": [ | ||
{ | ||
"coinDecimals": 6, | ||
"coinDenom": "NAM", | ||
"coinMinimalDenom": "namnam" | ||
} | ||
], | ||
"stakeCurrency": { | ||
"coinDecimals": 6, | ||
"coinDenom": "NAM", | ||
"coinMinimalDenom": "namnam" | ||
} | ||
} |
dcb53aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://namada-interface-dev.netlify.app as production
🚀 Deployed on https://66ec71062bb4564650cd20f7--namada-interface-dev.netlify.app