-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from nabla-studio/DavideSegullo/refactor-utils
Refactor Utils
- Loading branch information
Showing
19 changed files
with
379 additions
and
213 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
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export * from './keplr'; |
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,7 @@ | ||
import type { Chain } from '@nabla-studio/chain-registry'; | ||
|
||
export interface ChainInfoOptions { | ||
getRpcEndpoint: (chain: Chain) => string; | ||
getRestEndpoint: (chain: Chain) => string; | ||
getExplorer: (chain: Chain) => string; | ||
} |
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,32 @@ | ||
import type { Bech32Config } from '@keplr-wallet/types'; | ||
import type { Chain } from '@nabla-studio/chain-registry'; | ||
|
||
export const getRpc = (chain: Chain): string => | ||
chain.apis?.rpc?.[0]?.address ?? ''; | ||
|
||
export const getRest = (chain: Chain): string => | ||
chain.apis?.rest?.[0]?.address ?? ''; | ||
|
||
export const getExplr = (chain: Chain): string => | ||
chain.explorers?.[0]?.url ?? ''; | ||
|
||
/** | ||
* Returns bech32 address format as required by Keplr and other wallets | ||
* | ||
* @param prefix Chain bech32 prefix | ||
* @returns a valid `Bech32Config` | ||
*/ | ||
export const getBech32Config = ( | ||
prefix: string, | ||
validatorPrefix: string = 'val', | ||
consensusPrefix: string = 'cons', | ||
publicPrefix: string = 'pub', | ||
operatorPrefix: string = 'oper', | ||
): Bech32Config => ({ | ||
bech32PrefixAccAddr: prefix, | ||
bech32PrefixAccPub: `${prefix}${publicPrefix}`, | ||
bech32PrefixValAddr: `${prefix}${validatorPrefix}${operatorPrefix}`, | ||
bech32PrefixValPub: `${prefix}${validatorPrefix}${operatorPrefix}${publicPrefix}`, | ||
bech32PrefixConsAddr: `${prefix}${validatorPrefix}${consensusPrefix}`, | ||
bech32PrefixConsPub: `${prefix}${validatorPrefix}${consensusPrefix}${publicPrefix}`, | ||
}); |
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,3 @@ | ||
export * from './chain'; | ||
export * from './semver'; | ||
export * from './wallet'; |
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,40 @@ | ||
import { satisfies, extractVer, parseVer } from './semver'; | ||
|
||
const validVer = | ||
'osmosis-labs/[email protected]'; | ||
const validVer2 = 'osmosis-labs/[email protected]'; | ||
const invalidVer = 'osmosis-labs/cosmos-sdk'; | ||
|
||
const versionToCheck = '0.40.0'; | ||
|
||
test('extract valid version', () => { | ||
expect(extractVer(validVer)).toBe('0.45.0'); | ||
}); | ||
|
||
test('extract invalid version', () => { | ||
expect(extractVer(invalidVer)).toBe(null); | ||
}); | ||
|
||
test('parse version', () => { | ||
expect(parseVer(validVer)).toBe('0.45.0'); | ||
}); | ||
|
||
test('parse version with missing padding', () => { | ||
expect(parseVer(validVer2)).toBe('0.45.0'); | ||
}); | ||
|
||
test('satisfies compare gte', () => { | ||
expect(satisfies(versionToCheck, '>=0.40.0')).toBeTruthy(); | ||
}); | ||
|
||
test('satisfies compare lte', () => { | ||
expect(satisfies(versionToCheck, '<=0.40.0')).toBeTruthy(); | ||
}); | ||
|
||
test('satisfies compare lte falsy', () => { | ||
expect(satisfies(versionToCheck, '<=0.39.0')).toBeFalsy(); | ||
}); | ||
|
||
test('satisfies compare gte small version', () => { | ||
expect(satisfies(versionToCheck, '>=0.4.0')).toBeTruthy(); | ||
}); |
Oops, something went wrong.