Skip to content

Commit

Permalink
Merge pull request #205 from radixdlt/brave-support
Browse files Browse the repository at this point in the history
fix: add brave detection support
  • Loading branch information
xstelea authored Jun 3, 2024
2 parents ec2da62 + 8aee26a commit 75e7729
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<boolean> } | 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<Record<string, string>>(1)

const isCallbackUrl = () => window.location.href.includes(callBackPath)
Expand Down

0 comments on commit 75e7729

Please sign in to comment.