-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve pool type mapper safety by checking for unsupported types
- Loading branch information
1 parent
ef5c88d
commit 47f952b
Showing
4 changed files
with
18 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { PoolType } from '../types'; | ||
|
||
export const poolTypeFromApi = { | ||
// map pool type from the api to the sdk | ||
const poolTypeMap = { | ||
WEIGHTED: PoolType.Weighted, | ||
COMPOSABLE_STABLE: PoolType.ComposableStable, | ||
GYRO3: PoolType.Gyro3, | ||
GYRO2: PoolType.Gyro2, | ||
GYROE: PoolType.GyroE, | ||
}; | ||
|
||
export const mapPoolType = (type: string): PoolType => { | ||
const supportedPoolTypes = Object.keys(poolTypeMap); | ||
|
||
if (!supportedPoolTypes.includes(type)) { | ||
throw new Error(`Unsupported pool type ${type}`); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
brunoguerios
Author
Member
|
||
} | ||
|
||
return poolTypeMap[type]; | ||
}; |
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
@brunoguerios I would include
${supportedPoolTypes.join(',')}
in the error so that the consumer knows about the concrete supported types.