forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ELIZAAI-18 Added error handling, improved prompt data extracting, fix…
…ed denom fetching
- Loading branch information
1 parent
f0abcf5
commit 131e783
Showing
7 changed files
with
168 additions
and
113 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
35 changes: 35 additions & 0 deletions
35
packages/plugin-cosmos/src/actions/ibc-swap/services/utils.ts
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,35 @@ | ||
import { assets } from "chain-registry"; | ||
import BigNumber from "bignumber.js"; | ||
|
||
export const prepareAmbiguityErrorMessage = ( | ||
coinSymbol: string, | ||
chainName: string | ||
): string => { | ||
const chainAssets = assets.find((chain) => chain.chain_name === chainName); | ||
|
||
const ambiguousAssets = chainAssets.assets.filter( | ||
(asset) => asset.symbol === coinSymbol | ||
); | ||
|
||
console.log( | ||
`Ambiguous Assets found: ${JSON.stringify(ambiguousAssets, null, 2)}` | ||
); | ||
|
||
const assetsText = `${ambiguousAssets.map((a) => `Symbol: ${a.symbol} Desc: ${a.description} Denom: ${a.base}`).join(",\n")}`; | ||
|
||
return `Error occured. Swap was not performed. Please provide denom for coin: ${coinSymbol}, on Chain Name: ${chainName}. It is necessary as the symbol ${coinSymbol} is not unique among coins on chain ${chainName}. \n Select one from found assets:\n${assetsText}`; | ||
}; | ||
|
||
/** | ||
* Calculates amount passed in display unit | ||
* @param tokenAmount | ||
* @param exponet | ||
*/ | ||
export const calculateAmountInDenomFromDisplayUnit = ( | ||
tokenAmount: string, | ||
exponet: number | ||
) => { | ||
return new BigNumber(tokenAmount) | ||
.multipliedBy(new BigNumber(10).pow(exponet)) | ||
.toString(); | ||
}; |
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
Oops, something went wrong.