Skip to content

Commit

Permalink
Add try and catch to checkTrustline function
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanbelasich committed Feb 23, 2024
1 parent aca19b0 commit 6636059
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib/stellar/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6636059

Please sign in to comment.