Skip to content

Commit

Permalink
Merge pull request #718 from gmx-io/add-binance-wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
vipineth authored Dec 5, 2023
2 parents d427e37 + c4179c7 commit 03662a0
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 76 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@apollo/client": "3.5.6",
"@binance/w3w-utils": "1.0.1-alpha.0",
"@davatar/react": "1.8.1",
"@ethersproject/providers": "5.5.1",
"@ethersproject/units": "5.5.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/AddressDropdown/AddressDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Menu } from "@headlessui/react";
import { t, Trans } from "@lingui/macro";
import { ETH_MAINNET } from "config/chains";
import copy from "img/ic_copy_16.svg";
import externalLink from "img/ic_new_link_16.svg";
import externalLinkIcon from "img/ic_new_link_16.svg";
import disconnect from "img/ic_sign_out_16.svg";
import { helperToast } from "lib/helperToast";
import { useENS } from "lib/legacy";
Expand Down Expand Up @@ -57,7 +57,7 @@ function AddressDropdown({ account, accountUrl, disconnectAccountAndCloseSetting
</Menu.Item>
<Menu.Item>
<ExternalLink href={accountUrl} className="menu-item">
<img src={externalLink} alt="Open address in explorer" />
<img src={externalLinkIcon} alt="Open address in explorer" />
<p>
<Trans>View in Explorer</Trans>
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/lib/wallets/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { publicProvider } from "wagmi/providers/public";
import merge from "lodash/merge";
import { isDevelopment } from "config/env";
import { coreWallet } from "./connecters/core/coreWallet";
import { bitGetWallet } from "./connecters/bitGet/bitGetWallet";
import { bitgetWallet } from "./connecters/bitgetWallet/bitgetWallet";
import binanceWallet from "./connecters/binanceW3W/binanceWallet";

const WALLET_CONNECT_PROJECT_ID = "de24cddbaf2a68f027eae30d9bb5df58";
const APP_NAME = "GMX";
Expand Down Expand Up @@ -59,9 +60,10 @@ const othersWalletList: WalletList = [
wallets: [
coreWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
coinbaseWallet({ appName: APP_NAME, chains }),
binanceWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
ledgerWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
rainbowWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
bitGetWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
bitgetWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
imTokenWallet({ chains, projectId: WALLET_CONNECT_PROJECT_ID }),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/wallets/connecters/binanceW3W/binanceWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions src/lib/wallets/connecters/binanceW3W/binanceWallet.ts
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,
};
},
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Connector } from "wagmi/connectors";
import type { InjectedConnectorOptions } from "@wagmi/core/connectors/injected";
import { InjectedConnector } from "wagmi/connectors/injected";
import { Chain, Wallet, getWalletConnectConnector } from "@rainbow-me/rainbowkit";
import { getWalletConnectUri, isAndroid } from "../helper";

export interface BitKeepWalletLegacyOptions {
projectId?: string;
Expand All @@ -17,20 +17,7 @@ export interface BitKeepWalletOptions {
walletConnectOptions?: any;
}

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;
}

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 const bitGetWallet = ({
export const bitgetWallet = ({
chains,
projectId,
walletConnectOptions,
Expand All @@ -49,19 +36,19 @@ export const bitGetWallet = ({
const shouldUseWalletConnect = !isBitKeepInjected;

return {
id: "bitKeep",
id: "bitget",
name: "Bitget Wallet",
iconUrl: async () => (await import("./bitGetWallet.svg")).default,
iconUrl: async () => (await import("./bitgetWallet.svg")).default,
iconAccent: "#f6851a",
iconBackground: "#fff",
installed: !shouldUseWalletConnect ? isBitKeepInjected : undefined,
downloadUrls: {
android: "https://bitkeep.com/en/download?type=2",
android: "https://web3.bitget.com/en/wallet-download?type=0",
ios: "https://apps.apple.com/app/bitkeep/id1395301115",
mobile: "https://bitkeep.com/en/download?type=2",
qrCode: "https://bitkeep.com/en/download",
mobile: "https://web3.bitget.com/en/wallet-download?type=2",
qrCode: "https://web3.bitget.com/en/wallet-download",
chrome: "https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak",
browserExtension: "https://bitkeep.com/en/download",
browserExtension: "https://web3.bitget.com/en/wallet-download",
},

createConnector: () => {
Expand Down Expand Up @@ -91,12 +78,12 @@ export const bitGetWallet = ({
connector,
extension: {
instructions: {
learnMoreUrl: "https://study.bitkeep.com",
learnMoreUrl: "https://web3.bitget.com/en/academy",
steps: [
{
description: "We recommend pinning BitKeep to your taskbar for quicker access to your wallet.",
description: "We recommend pinning Bitget Wallet to your taskbar for quicker access to your wallet.",
step: "install",
title: "Install the BitKeep extension",
title: "Install the Bitget Wallet extension",
},
{
description:
Expand All @@ -120,12 +107,12 @@ export const bitGetWallet = ({
? {
getUri: async () => getWalletConnectUri(connector, walletConnectVersion),
instructions: {
learnMoreUrl: "https://study.bitkeep.com",
learnMoreUrl: "https://web3.bitget.com/en/academy",
steps: [
{
description: "We recommend putting BitKeep on your home screen for quicker access.",
description: "We recommend putting Bitget Wallet on your home screen for quicker access.",
step: "install",
title: "Open the BitKeep app",
title: "Open the Bitget Wallet app",
},
{
description:
Expand Down
9 changes: 1 addition & 8 deletions src/lib/wallets/connecters/core/coreWallet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import type { Connector } from "wagmi/connectors";
import type { InjectedConnectorOptions } from "@wagmi/core/connectors/injected";
import { InjectedConnector } from "wagmi/connectors/injected";
import { Chain, Wallet, getWalletConnectConnector } from "@rainbow-me/rainbowkit";

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;
}
import { getWalletConnectUri } from "../helper";

export interface CoreWalletLegacyOptions {
projectId?: string;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/wallets/connecters/helper.ts
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;
}
4 changes: 0 additions & 4 deletions src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "Liquiditätsdaten nicht geladen"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2581,10 +2581,6 @@ msgstr "Liquidity and trading incentives program is live on Arbitrum. <0>Read mo
msgid "Liquidity data not loaded"
msgstr "Liquidity data not loaded"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr "Liquidity incentives program is live. <0>Read more</0>."

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "Datos de liquidez no cargados"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "Les données de liquidité ne sont pas chargées"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "流動性データがロードされていません"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "유동성 데이터를 불러오지 못하였습니다."

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/pseudo/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr ""

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/ru/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "Данные о ликвидности не загружены"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
4 changes: 0 additions & 4 deletions src/locales/zh/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ msgstr ""
msgid "Liquidity data not loaded"
msgstr "未加载流动资金数据"

#: src/pages/Stake/StakeV2.js
#~ msgid "Liquidity incentives program is live. <0>Read more</0>."
#~ msgstr ""

#: src/components/Exchange/PositionsList.js
#: src/components/Exchange/PositionsList.js
#: src/components/Synthetics/Claims/Claims.tsx
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
Loading

0 comments on commit 03662a0

Please sign in to comment.