From 8aee26ad16917a8698b5b29233fd000655039348 Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Thu, 30 May 2024 17:31:01 +0100 Subject: [PATCH] fix: add brave detection support --- .../radix-connect-relay/deep-link.module.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts index 54924169..e2f5b5be 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts @@ -1,4 +1,4 @@ -import type { Result, ResultAsync } from 'neverthrow' +import { Result, ResultAsync } from 'neverthrow' import { errAsync, ok, okAsync } from 'neverthrow' import { Logger } from '../../../../helpers' import { ReplaySubject } from 'rxjs' @@ -16,6 +16,27 @@ export const DeepLinkModule = (input: { const { platform, browser } = userAgent const logger = input?.logger?.getSubLogger({ name: 'DeepLinkModule' }) + const getNavigator = (): Navigator | undefined => globalThis?.navigator + + // Only exists in Brave browser + const getBrave = (): { isBrave: () => Promise } | undefined => + (getNavigator() as any)?.brave + + const isBrave = () => { + const maybeBrave = getBrave() + return maybeBrave + ? ResultAsync.fromPromise(maybeBrave.isBrave(), (error) => error as Error) + : okAsync(false) + } + + isBrave().map((isBrave) => { + if (isBrave) { + browser.name = 'Brave' + } + + logger?.debug({ platform, browser }) + }) + const walletResponseSubject = new ReplaySubject>(1) const isCallbackUrl = () => window.location.href.includes(callBackPath)