Skip to content

Commit

Permalink
Merge pull request #1801 from synonymdev/new-bt-server
Browse files Browse the repository at this point in the history
fix: use blocktank host env var to setup client
  • Loading branch information
Jasonvdb authored May 8, 2024
2 parents dd81473 + 63a6cda commit f69dfa6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/store/types/blocktank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export type TPaidBlocktankOrders = {
[orderId: string]: string;
};

export type TGeoBlockResponse = { error?: 'GEO_BLOCKED'; accept?: boolean };

export interface ICreateOrderRequest {
lspBalance: number;
channelExpiryWeeks?: number;
Expand Down
29 changes: 18 additions & 11 deletions src/utils/blocktank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import {
import { sleep } from '../helpers';
import { DEFAULT_CHANNEL_DURATION } from '../../utils/wallet/constants';
import { dispatch, getBlocktankStore, getUserStore } from '../../store/helpers';
import {
ICreateOrderRequest,
TGeoBlockResponse,
} from '../../store/types/blocktank';
import { ICreateOrderRequest } from '../../store/types/blocktank';
import { updateUser } from '../../store/slices/user';
import { setGeoBlock } from '../../store/utils/user';
import { refreshWallet } from '../wallet';
Expand All @@ -41,7 +38,7 @@ export const setupBlocktank = async (
switch (selectedNetwork) {
case EAvailableNetwork.bitcoin:
isGeoBlocked = await setGeoBlock();
bt.baseUrl = 'https://blocktank.synonym.to/api/v2';
bt.baseUrl = __BLOCKTANK_HOST__;
break;
case EAvailableNetwork.bitcoinRegtest:
dispatch(updateUser({ isGeoBlocked: false }));
Expand Down Expand Up @@ -350,12 +347,22 @@ export const isGeoBlocked = async (fromStorage = false): Promise<boolean> => {
return geoBlocked;
}
}
const response = await fetch(
`${__BLOCKTANK_HOST__}/api/v2/channel/geocheck`,
);
const data: TGeoBlockResponse = await response.json();
return !!data?.error;
} catch {

const response = await fetch(`${__BLOCKTANK_HOST__}/geocheck`);

if (response.status === 403) {
return true;
}

if (response.status === 200) {
return false;
}

console.error(`Geo-block status check failed. [${response.status}]`);

return false;
} catch (error) {
console.error(`Failed to check geo-block status. ${error}`);
return false;
}
};
Expand Down

0 comments on commit f69dfa6

Please sign in to comment.