feat: add getAddressFrom

This commit is contained in:
Kyle Fang
2023-08-01 11:01:33 +08:00
parent fc430b7158
commit ad15b41761
3 changed files with 14 additions and 1 deletions

View File

@@ -76,6 +76,14 @@ Get the corresponding currency for a given address.
function getCurrencyFrom(address: string): Currency | undefined; function getCurrencyFrom(address: string): Currency | undefined;
``` ```
### getAddressFrom
Get the corresponding currency for a given address.
```javascript
function getAddressFrom(currency: Exclude<Currency, Currency.STX>): string;
```
### isAlexSwapTransaction ### isAlexSwapTransaction
Check if a transaction is a swap transaction from Alex Check if a transaction is a swap transaction from Alex

View File

@@ -7,6 +7,7 @@ import { runSpot, TxToBroadCast } from './helpers/SwapHelper';
import { import {
fetchBalanceForAccount, fetchBalanceForAccount,
findCurrencyByNativeAddress, findCurrencyByNativeAddress,
getCurrencyNativeAddress,
} from './utils/currencyUtils'; } from './utils/currencyUtils';
import { fetchLatestPrices } from './utils/currencyPrice'; import { fetchLatestPrices } from './utils/currencyPrice';
import { assignConfig, AssignConfigParams, configs } from './config'; import { assignConfig, AssignConfigParams, configs } from './config';
@@ -72,6 +73,10 @@ export class AlexSDK {
return findCurrencyByNativeAddress(address); return findCurrencyByNativeAddress(address);
} }
getAddressFrom(currency: Exclude<Currency, Currency.STX>): string {
return getCurrencyNativeAddress(currency);
}
getLatestPrices(): Promise< getLatestPrices(): Promise<
Partial<{ Partial<{
[currency in Currency]: number; [currency in Currency]: number;

View File

@@ -11,7 +11,7 @@ export function getCurrencyNativeScale(currency: Currency) {
export function getCurrencyNativeAddress(currency: Currency) { export function getCurrencyNativeAddress(currency: Currency) {
if (currency === Currency.STX) { if (currency === Currency.STX) {
throw new Error('STX is not a token'); throw new Error('STX does not have an address');
} }
return configs.NATIVE_TOKEN_MAPPING[currency].assetIdentifier; return configs.NATIVE_TOKEN_MAPPING[currency].assetIdentifier;
} }