Skip to content

Commit

Permalink
feat: Support binance web3 wallet on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Feb 4, 2024
1 parent 7a4ad5a commit c33fbda
Show file tree
Hide file tree
Showing 9 changed files with 5,566 additions and 1,806 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-hats-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@node-real/walletkit": patch
---

Support binance web3 wallet on mobile
14 changes: 14 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: 'setup'
description: Prepare the environment

inputs:
npm_token:
description: 'npm token'
required: true

runs:
using: composite
steps:
Expand All @@ -23,3 +28,12 @@ runs:
- name: Install dependencies
shell: bash
run: pnpm install

- name: Creating .npmrc
shell: bash
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ inputs.npm_token }}
26 changes: 6 additions & 20 deletions .github/workflows/release.yaml → .github/workflows/alpha.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Release
name: Alpha release
on:
push:
branches:
- main
- alpha
- 0.x
- 0.x-alpha

jobs:
Expand All @@ -20,32 +18,20 @@ jobs:
fetch-depth: 0

- uses: ./.github/actions/setup
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Build packages
run: pnpm build

- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Enter pre mode
if: github.ref_name == 'alpha' || github.ref_name == '0.x-alpha'
run: |
pnpm ci:enter | exit 0
- name: Exit pre mode
if: github.ref_name == 'main' || github.ref_name == '0.x'
run: |
pnpm ci:exit | exit 0
if: github.event.commits[0].author.username != 'github-actions[bot]'
run: pnpm ci:enter

- name: Create and publish versions
uses: changesets/action@v1
with:
version: pnpm ci:version
version: pnpm ci:alpha-version
publish: pnpm ci:publish
commit: 'chore: update versions'
title: 'chore: update versions'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
jobs:
release:
name: deploy docs
if: github.repository == 'node-real/walletkit'
if: |
github.repository == 'node-real/walletkit' &&
github.event.commits[0].author.username != 'github-actions[bot]'
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Stable Release
on:
push:
branches:
- main
- 0.x

jobs:
release:
name: release
if: github.repository == 'node-real/walletkit'
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Checkout code repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: ./.github/actions/setup
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Build packages
run: pnpm build

- name: Exit pre mode
if: github.event.commits[0].author.username != 'github-actions[bot]'
run: pnpm ci:exit

- name: Create and publish versions
uses: changesets/action@v1
with:
version: pnpm ci:stable-version
publish: pnpm ci:publish
commit: 'chore: update versions'
title: 'chore: update versions'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"build": "pnpm --F @node-real/walletkit build",
"dev:docs": "pnpm --F @node-real/walletkit build:watch & pnpm --F website dev",
"build:docs": "pnpm build && pnpm --F website build",
"ci:enter": "pnpm changeset pre enter alpha",
"ci:exit": "pnpm changeset pre exit",
"ci:enter": "pnpm changeset pre enter alpha || true",
"ci:exit": "pnpm changeset pre exit || true",
"ci:version": "pnpm changeset version && cp README.md packages/walletkit/README.md",
"ci:publish": "pnpm changeset publish"
"ci:publish": "pnpm changeset publish",
"ci:alpha-version": "pnpm ci:enter && pnpm ci:version",
"ci:stable-version": "pnpm ci:exit && pnpm ci:version"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/walletkit/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Connector as WagmiConnector } from 'wagmi';

import type { InjectedProviderFlags as WagmiInjectedProviderFlags } from 'wagmi/window';

import { WalletProps } from './wallets/types';

declare global {
Expand All @@ -17,3 +19,9 @@ declare module 'wagmi' {
_wallet: WalletProps;
}
}

declare module 'wagmi/window' {
type InjectedProviderFlags = WagmiInjectedProviderFlags & {
isBinance?: string | undefined;
};
}
21 changes: 17 additions & 4 deletions packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PartialCustomProps, WalletProps } from '..';
import { CustomConnector } from '../custom/connector';
import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon';
import { isMobile } from '@/base/utils/mobile';
import { hasInjectedProvider } from '../utils';

export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet';

Expand Down Expand Up @@ -41,7 +42,8 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
});
},
getDeepLink: () => {
return undefined; //`bnc://app.binance.com/cedefi/wc?uri=${encodeURIComponent(uri)}`;
const { bnc } = getDeepLink(window.location.href);
return bnc;
},
getQRCodeUri(uri) {
return uri;
Expand All @@ -51,7 +53,18 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
}

export function isBinanceWeb3Wallet() {
if (typeof window === 'undefined') return false;

return false;
return hasInjectedProvider('isBinance' as any);
}

const getDeepLink = (url: string) => {
const base = 'bnc://app.binance.com/mp/app';
const appId = 'yFK5FCqYprrXDiVFbhyRx7';

const startPagePath = window.btoa('/pages/browser/index');
const startPageQuery = window.btoa(`url=${url}`);
const deeplink = `${base}?appId=${appId}&startPagePath=${startPagePath}&startPageQuery=${startPageQuery}`;
const dp = window.btoa(deeplink);
const http = `https://app.binance.com/en/download?_dp=${dp}`;

return { http, bnc: deeplink };
};
Loading

0 comments on commit c33fbda

Please sign in to comment.