55 UnsupportedTokenError ,
66 UtilsError ,
77} from '@bitgo/sdk-core' ;
8- import { coins , XrpCoin } from '@bitgo/statics' ;
8+ import { BaseCoin , coins , XrpCoin } from '@bitgo/statics' ;
99import * as querystring from 'querystring' ;
1010import * as rippleKeypairs from 'ripple-keypairs' ;
1111import * as url from 'url' ;
@@ -14,6 +14,7 @@ import { Amount, IssuedCurrencyAmount } from 'xrpl';
1414import { VALID_ACCOUNT_SET_FLAGS } from './constants' ;
1515import { Address , SignerDetails } from './iface' ;
1616import { KeyPair as XrpKeyPair } from './keyPair' ;
17+ import assert from 'assert' ;
1718
1819class Utils implements BaseUtils {
1920 isValidAddress ( address : string ) : boolean {
@@ -267,6 +268,29 @@ class Utils implements BaseUtils {
267268 throw new Error ( `Failed to decode transaction: ${ error . message } ` ) ;
268269 }
269270 }
271+
272+ /**
273+ * Get the statics coin object matching a given Xrp token issuer address and currency code if it exists
274+ *
275+ * @param issuerAddress The token issuer address to match against
276+ * @param currencyCode The token currency code to match against
277+ * @returns statics BaseCoin object for the matching token
278+ */
279+ public getXrpToken ( issuerAddress , currencyCode ) : Readonly < BaseCoin > | undefined {
280+ const tokens = coins . filter ( ( coin ) => {
281+ if ( coin instanceof XrpCoin ) {
282+ return coin . issuerAddress === issuerAddress && coin . currencyCode === currencyCode ;
283+ }
284+ return false ;
285+ } ) ;
286+ const tokensArray = tokens . map ( ( token ) => token ) ;
287+ if ( tokensArray . length >= 1 ) {
288+ // there should never be two tokens with the same issuer address and currency code, so we assert that here
289+ assert ( tokensArray . length === 1 ) ;
290+ return tokensArray [ 0 ] ;
291+ }
292+ return undefined ;
293+ }
270294}
271295
272296const utils = new Utils ( ) ;
0 commit comments