Skip to content

Commit

Permalink
fix: only use api on mainnet (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
anondev2323 authored May 1, 2023
1 parent 7fedd91 commit dd636aa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wormhole-connect/src/utils/transferValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../store/transfer';
import { WalletData, WalletState } from '../store/wallet';
import { walletAcceptedNetworks } from './wallet';
import { CHAINS, TOKENS } from '../config';
import { CHAINS, TOKENS, WH_CONFIG } from '../config';
import { PaymentOption } from '../sdk';

export type ValidationErr = string;
Expand Down Expand Up @@ -88,20 +88,24 @@ async function checkAddressIsSanctioned(address: string): Promise<boolean> {
if (trmCache[address]) {
return trmCache[address].isSanctioned;
}
const defaultAuth =
'Basic ' + Buffer.from('<username>:<password>').toString('base64');
const res = await fetch(
`https://api.trmlabs.com/public/v1/sanctions/screening`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization:
'Basic ' + Buffer.from('<username>:<password>').toString('base64'),
process.env.REACT_APP_TRM_API_KEY && WH_CONFIG.env === 'MAINNET'
? process.env.REACT_APP_TRM_API_KEY
: defaultAuth,
},
body: JSON.stringify([{ address }]),
},
);

if (res.status !== 200) {
if (res.status !== 200 && res.status !== 201) {
// set cache so it stops making requests
if (res.status === 429) {
trmCache[address] = {
Expand Down

0 comments on commit dd636aa

Please sign in to comment.