-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use mobile-connector when dApp is launched within a mobile app (#…
…471)
- Loading branch information
Showing
4 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@starknet-react/core": minor | ||
--- | ||
|
||
use mobile-connector when dApp is launched within an in-app mobile browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Connector } from "~/connectors/base"; | ||
import { braavos } from "~/connectors/helpers"; | ||
|
||
export const isMobile = (): boolean => { | ||
const userAgent = | ||
typeof window !== "undefined" ? window.navigator?.userAgent : ""; | ||
return /Android|iPhone|iPad|iPod/i.test(userAgent); | ||
}; | ||
|
||
export const withMobileConnector = (connectors: Connector[]): Connector[] => { | ||
if ( | ||
isMobile() && | ||
// In the context of a mobile browser, `starknet_braavos` is only injected | ||
// if the dApp is launched within the Braavos in-app dApp browser | ||
!!window.starknet_braavos | ||
) { | ||
return [braavos()]; | ||
} | ||
|
||
return connectors; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters