diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 71c64b2675..d187faa4bf 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -22,6 +22,7 @@ interface AccountContextType { avatarUrl?: AccountInfo["avatarUrl"]; connectorType?: AccountInfo["connectorType"]; lightningAddress?: AccountInfo["lightningAddress"]; + nodeRequired?: AccountInfo["nodeRequired"]; } | null; balancesDecorated: { fiatBalance: string; diff --git a/src/app/screens/Home/DefaultView/index.tsx b/src/app/screens/Home/DefaultView/index.tsx index aa6ba044c3..7418420d33 100644 --- a/src/app/screens/Home/DefaultView/index.tsx +++ b/src/app/screens/Home/DefaultView/index.tsx @@ -122,9 +122,9 @@ const DefaultView: FC = (props) => { )} -
+
{isBlockedUrl && ( -
+

{t("default_view.is_blocked_hint", { @@ -165,8 +165,33 @@ const DefaultView: FC = (props) => {

)} + {account?.nodeRequired ? ( + +
+
+ +
+ + , + ]} + /> + +
+
+ ) : ( + + )} - {(accountLoading || lightningAddress) && (
+ GetInfoResponse > { const cacheKey = "getInfo"; const cacheValue = this._cache.get(cacheKey) as GetInfoResponse< - WebLNNode & GetAccountInformationResponse + WebLNNode & GetAccountInformationResponses >; - if (cacheValue) { + + const node_required = await this._isNodeRequired(); + + if (cacheValue && cacheValue.data.node_required === node_required) { return cacheValue; } @@ -130,9 +152,11 @@ export default class Alby implements Connector { const info = await this._request((client) => client.accountInformation({}) ); + const returnValue = { data: { ...info, + node_required: node_required, alias: "🐝 getalby.com", }, }; @@ -406,4 +430,45 @@ export default class Alby implements Connector { throw new Error("Invalid token"); } } + + private async _isNodeRequired() { + const url = `${process.env.ALBY_API_URL}/internal/users`; + + const requestOptions = { + method: "GET", + headers: { + "Content-Type": "application/json", + ...(await this._authUser?.getAuthHeader()), + "User-Agent": `lightning-browser-extension:${process.env.VERSION}`, + "X-User-Agent": `lightning-browser-extension:${process.env.VERSION}`, + }, + }; + + try { + const details = await this._genericRequest( + url, + requestOptions + ); + + return details.node_required; + } catch (error) { + console.error("Error fetching limits:", error); + throw error; + } + } + + private async _genericRequest( + url: RequestInfo, + init: RequestInit + ): Promise { + const res = await fetch(url, init); + + if (!res.ok) { + throw new Error(`HTTP error! status: ${res.status}`); + } + + const data: T = await res.json(); + + return data; + } } diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 62af848783..6f2d44102a 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -384,6 +384,7 @@ "description": "Fund your account and receive via your lightning address or an invoice" } }, + "node_required": "Your Alby Account needs a wallet. Connect a wallet to your account on <0>getalby.com", "upgrade_account": "You are using the old LNDHub setup. <0>Please re-connect your Alby account to get access to the latest features." } }, diff --git a/src/types.ts b/src/types.ts index 7b5abb239b..f27d51d599 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,7 @@ -import { CreateSwapParams } from "@getalby/sdk/dist/types"; +import { + CreateSwapParams, + GetAccountInformationResponse, +} from "@getalby/sdk/dist/types"; import { PaymentRequestObject } from "bolt11-signet"; import { Runtime } from "webextension-polyfill"; import { ACCOUNT_CURRENCIES, CURRENCIES } from "~/common/constants"; @@ -46,8 +49,13 @@ export interface AccountInfo { currency: ACCOUNT_CURRENCIES; avatarUrl?: string; lightningAddress?: string; + nodeRequired?: boolean; } +export type GetAccountInformationResponses = GetAccountInformationResponse & { + node_required?: boolean; +}; + export interface MetaData { title?: string; description?: string;