-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from gmx-io/add-binance-wallet
- Loading branch information
Showing
20 changed files
with
170 additions
and
76 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,96 @@ | ||
import type { InjectedConnectorOptions } from "@wagmi/core/connectors/injected"; | ||
import { InjectedConnector } from "wagmi/connectors/injected"; | ||
import { Chain, Wallet, getWalletConnectConnector } from "@rainbow-me/rainbowkit"; | ||
import { getWalletConnectUri } from "../helper"; | ||
import { getHref, isInBinance } from "@binance/w3w-utils"; | ||
|
||
export interface BinanceW3WOptions { | ||
projectId: string; | ||
chains: Chain[]; | ||
walletConnectOptions?: any; | ||
} | ||
|
||
export default function binanceWallet({ | ||
chains, | ||
projectId, | ||
walletConnectOptions, | ||
...options | ||
}: BinanceW3WOptions & InjectedConnectorOptions): Wallet { | ||
const shouldUseWalletConnect = !isInBinance(); | ||
const provider = typeof window !== "undefined" && isInBinance() ? window.ethereum : undefined; | ||
return { | ||
id: "binance", | ||
name: "Binance Wallet", | ||
iconUrl: async () => (await import("./binanceWallet.svg")).default, | ||
iconAccent: "#1E1E1E", | ||
iconBackground: "#1E1E1E", | ||
installed: isInBinance() || undefined, | ||
downloadUrls: { | ||
android: "https://play.google.com/store/apps/details?id=com.binance.dev", | ||
ios: "https://apps.apple.com/us/app/binance-buy-bitcoin-crypto/id1436799971", | ||
mobile: "https://www.binance.com/en/download", | ||
qrCode: "https://www.binance.com/en/download", | ||
}, | ||
|
||
createConnector: () => { | ||
const connector = shouldUseWalletConnect | ||
? getWalletConnectConnector({ | ||
chains, | ||
options: walletConnectOptions, | ||
projectId, | ||
version: "2", | ||
...options, | ||
}) | ||
: new InjectedConnector({ | ||
chains, | ||
options: { | ||
getProvider: () => provider, | ||
...options, | ||
}, | ||
}); | ||
|
||
const getUriMobile = async () => { | ||
const uri = await getWalletConnectUri(connector, "2"); | ||
return getHref(true, uri); | ||
}; | ||
|
||
const getUriQR = async () => { | ||
const uri = await getWalletConnectUri(connector, "2"); | ||
return uri; | ||
}; | ||
|
||
return { | ||
connector, | ||
mobile: { | ||
getUri: shouldUseWalletConnect ? getUriMobile : undefined, | ||
}, | ||
qrCode: shouldUseWalletConnect | ||
? { | ||
getUri: getUriQR, | ||
instructions: { | ||
learnMoreUrl: | ||
"https://www.binance.com/en/blog/markets/introducing-binance-web3-wallet-5931309459106555347", | ||
steps: [ | ||
{ | ||
description: "Log in to your Binance app and tap [Wallets]. Go to [Web3].", | ||
step: "install", | ||
title: "Open Binance app", | ||
}, | ||
{ | ||
description: "Tap [Create Wallet] to start using your Web3 Wallet.", | ||
step: "create", | ||
title: "Create or Import a Wallet", | ||
}, | ||
{ | ||
description: "After you scan, a connection prompt will appear for you to connect your wallet.", | ||
step: "scan", | ||
title: "Tap the scan button", | ||
}, | ||
], | ||
}, | ||
} | ||
: undefined, | ||
}; | ||
}, | ||
}; | ||
} |
File renamed without changes
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
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,14 @@ | ||
import type { Connector } from "wagmi/connectors"; | ||
|
||
export function isAndroid(): boolean { | ||
return ( | ||
typeof navigator !== "undefined" && /Android\s([0-9.]+)/.test(navigator.userAgent) // Source: https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts | ||
); | ||
} | ||
|
||
export async function getWalletConnectUri(connector: Connector, version: "1" | "2"): Promise<string> { | ||
const provider = await connector.getProvider(); | ||
return version === "2" | ||
? new Promise<string>((resolve) => provider.once("display_uri", resolve)) | ||
: provider.connector.uri; | ||
} |
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
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
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
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
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
Oops, something went wrong.