Skip to content

Commit

Permalink
backend: add /dev-servers endpoint
Browse files Browse the repository at this point in the history
and use it in the frontend to correctly set the BTCDirect widget params.
  • Loading branch information
Beerosagos committed Feb 4, 2025
1 parent 92ca545 commit e86b9b0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions backend/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func NewHandlers(
getAPIRouterNoError(apiRouter)("/detect-dark-theme", handlers.getDetectDarkTheme).Methods("GET")
getAPIRouterNoError(apiRouter)("/version", handlers.getVersion).Methods("GET")
getAPIRouterNoError(apiRouter)("/testing", handlers.getTesting).Methods("GET")
getAPIRouterNoError(apiRouter)("/dev-servers", handlers.getDevServers).Methods("GET")
getAPIRouterNoError(apiRouter)("/account-add", handlers.postAddAccount).Methods("POST")
getAPIRouterNoError(apiRouter)("/keystores", handlers.getKeystores).Methods("GET")
getAPIRouterNoError(apiRouter)("/accounts", handlers.getAccounts).Methods("GET")
Expand Down Expand Up @@ -541,6 +542,10 @@ func (handlers *Handlers) getTesting(*http.Request) interface{} {
return handlers.backend.Testing()
}

func (handlers *Handlers) getDevServers(*http.Request) interface{} {
return handlers.backend.DevServers()
}

func (handlers *Handlers) postAddAccount(r *http.Request) interface{} {
var jsonBody struct {
CoinCode coinpkg.Code `json:"coinCode"`
Expand Down
4 changes: 4 additions & 0 deletions frontends/web/src/api/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const getTesting = (): Promise<boolean> => {
return apiGet('testing');
};

export const getDevServers = (): Promise<boolean> => {
return apiGet('dev-servers');
};

export type TQRCode = FailResponse | (SuccessResponse & { data: string; });

export const getQRCode = (data: string) => {
Expand Down
1 change: 1 addition & 0 deletions frontends/web/src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type AppContextProps = {
guideExists: boolean;
hideAmounts: boolean;
isTesting: boolean;
isDevServers: boolean;
nativeLocale: string;
sidebarStatus: TSidebarStatus;
firmwareUpdateDialogOpen: boolean;
Expand Down
4 changes: 3 additions & 1 deletion frontends/web/src/contexts/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AppContext } from './AppContext';
import { useLoad } from '@/hooks/api';
import { useDefault } from '@/hooks/default';
import { getNativeLocale } from '@/api/nativelocale';
import { getTesting } from '@/api/backend';
import { getDevServers, getTesting } from '@/api/backend';
import { i18nextFormat } from '@/i18n/utils';
import type { TChartDisplay, TSidebarStatus } from './AppContext';

Expand All @@ -31,6 +31,7 @@ type TProps = {
export const AppProvider = ({ children }: TProps) => {
const nativeLocale = i18nextFormat(useDefault(useLoad(getNativeLocale), 'de-CH'));
const isTesting = useDefault(useLoad(getTesting), false);
const isDevServers = useDefault(useLoad(getDevServers), false);
const [guideShown, setGuideShown] = useState(false);
const [guideExists, setGuideExists] = useState(false);
const [hideAmounts, setHideAmounts] = useState(false);
Expand Down Expand Up @@ -77,6 +78,7 @@ export const AppProvider = ({ children }: TProps) => {
guideExists,
hideAmounts,
isTesting,
isDevServers,
nativeLocale,
sidebarStatus,
chartDisplay,
Expand Down
6 changes: 2 additions & 4 deletions frontends/web/src/routes/exchange/btcdirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { useLoad } from '@/hooks/api';
import { useDarkmode } from '@/hooks/darkmode';
import { UseDisableBackButton } from '@/hooks/backbutton';
import { getConfig } from '@/utils/config';
import { debug } from '@/utils/env';
import { Header } from '@/components/layout';
import { Spinner } from '@/components/spinner/Spinner';
import { findAccount, getCoinCode, isBitcoinOnly } from '@/routes/account/utils';
Expand All @@ -47,7 +46,7 @@ type TProps = {

export const BTCDirect = ({ accounts, code }: TProps) => {
const { i18n, t } = useTranslation();
const { isTesting } = useContext(AppContext);
const { isDevServers } = useContext(AppContext);
const { isDarkMode } = useDarkmode();

const iframeRef = useRef<HTMLIFrameElement | null>(null);
Expand Down Expand Up @@ -136,8 +135,7 @@ export const BTCDirect = ({ accounts, code }: TProps) => {
data-base-currency={getCoinCode(account.coinCode)}
data-quote-currency={'EUR'}
data-address={btcdirectInfo.address}
data-mode={
isTesting || debug ? 'debug' : 'production'
data-mode={isDevServers ? 'debug' : 'production'
}
data-api-key={btcdirectInfo.apiKey}
src={btcdirectInfo.url}>
Expand Down

0 comments on commit e86b9b0

Please sign in to comment.