Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use blocktank host env var to setup client #1801

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading