diff --git a/src/lib/stellar/Payment.ts b/src/lib/stellar/Payment.ts index 8315088..3c98f73 100644 --- a/src/lib/stellar/Payment.ts +++ b/src/lib/stellar/Payment.ts @@ -4,21 +4,21 @@ import { CURRENT_NETWORK_PASSPHRASE } from './StellarNetwork'; import { server } from './utils'; export async function checkTrustline(receiver: string, assetCode: string, issuer: string) { - const account = await server.loadAccount(receiver); + try { + const account = await server.loadAccount(receiver); - for (const balance of account.balances) { - if (assetCode === 'native') { - if ('asset_type' in balance && balance.asset_type === 'native') { - return true; - } - } else if ('asset_code' in balance && 'asset_issuer' in balance) { - if (balance.asset_code === assetCode && balance.asset_issuer === issuer) { + for (const balance of account.balances) { + if ( + (assetCode === 'native' && balance.asset_type === 'native') || + ('asset_code' in balance && balance.asset_code === assetCode && balance.asset_issuer === issuer) + ) { return true; } } + return false; + } catch (error) { + throw new Error(JSON.stringify(error)); } - - return false; } export async function createPaymentTransaction(