-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): ListCurrencies enhancement
Closes #1067.
- Loading branch information
Showing
12 changed files
with
208 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { callback, loadXudClient } from '../command'; | ||
import { Arguments } from 'yargs'; | ||
import colors from 'colors/safe'; | ||
import Table, { HorizontalTable } from 'cli-table3'; | ||
import { ListCurrenciesRequest, ListCurrenciesResponse } from '../../proto/xudrpc_pb'; | ||
import { SwapClientType } from '../../constants/enums'; | ||
|
||
const HEADERS = [ | ||
colors.blue('Ticker'), | ||
colors.blue('Digits'), | ||
colors.blue('Token Address'), | ||
colors.blue('Swap Client'), | ||
]; | ||
|
||
const formatCurrencies = (currencies: ListCurrenciesResponse.AsObject) => { | ||
const formatted: any[] = []; | ||
currencies.currenciesList.forEach((currency) => { | ||
const element = []; | ||
element.push(currency.currency, currency.decimalPlaces, currency.tokenAddress, SwapClientType[currency.swapClient]); | ||
formatted.push(element); | ||
}); | ||
return formatted; | ||
}; | ||
|
||
const createTable = () => { | ||
const table = new Table({ | ||
head: HEADERS, | ||
}) as HorizontalTable; | ||
return table; | ||
}; | ||
|
||
const displayTable = (response: ListCurrenciesResponse.AsObject) => { | ||
const table = createTable(); | ||
|
||
formatCurrencies(response).forEach((currency) => { | ||
table.push(currency); | ||
}); | ||
console.log(colors.underline(colors.bold('\nCurrencies:'))); | ||
console.log(table.toString()); | ||
}; | ||
|
||
export const command = 'listcurrencies'; | ||
|
||
export const describe = 'list available currencies'; | ||
|
||
export const handler = (argv: Arguments) => { | ||
loadXudClient(argv).listCurrencies(new ListCurrenciesRequest(), callback(argv, displayTable)); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.