Skip to content

Commit

Permalink
Alpha (#155)
Browse files Browse the repository at this point in the history
* fix: Fixed binance web3 wallet disconnect after refresh page (#151)

* test: Test binance web3 wallet

* test: Test binance web3 wallet

* test: Test binance web3 wallet

* test: Test

* test: Test

* test: Test

* test: Test binance web3 wallet

* test: Test

* test: Test binance web3 wallet

* docs: Add log

* test: Test binance web3 wallet

* test: Test

* test: Test

* test: Test

* Dev (#153)

* test: Test binance web3 wallet

* test: Test binance web3 wallet

* test: Test binance web3 wallet

* test: Test

* test: Test

* test: Test

* test: Test binance web3 wallet

* test: Test

* test: Test binance web3 wallet

* docs: Add log

* test: Test binance web3 wallet

* test: Test

* test: Test

* test: Test

* refactor: Remove unused code

* docs: Add log

* chore: update versions (alpha) (#154)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent 024f91f commit b11c309
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-doors-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@node-real/walletkit": patch
---

Fixed binance web3 wallet disconnect after refresh page.
5 changes: 5 additions & 0 deletions .changeset/nervous-badgers-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@node-real/walletkit": patch
---

Remove unused code
14 changes: 14 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"example-nextjs": "0.0.1",
"example-vite": "0.0.1",
"@node-real/walletkit": "1.0.12",
"website": "0.0.1"
},
"changesets": [
"gold-doors-check",
"nervous-badgers-raise"
]
}
1 change: 1 addition & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- main
- alpha
- dev

jobs:
release:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"author": "node-real",
"private": true,
"packageManager": "pnpm@8.9.2",
"packageManager": "pnpm@9.1.1",
"description": "Toolkit for connecting wallets.",
"license": "MIT",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions packages/walletkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @node-real/walletkit

## 1.0.13-alpha.0

### Patch Changes

- 237726b: Fixed binance web3 wallet disconnect after refresh page.
- 8b9e4fe: Remove unused code

## 1.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/walletkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-real/walletkit",
"version": "1.0.12",
"version": "1.0.13-alpha.0",
"author": "node-real",
"private": false,
"description": "WalletKit is a React component library for easily connecting a wallet to your dApp.",
Expand Down
52 changes: 52 additions & 0 deletions packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { sleep } from '@/utils/common';
import { Chain } from 'wagmi';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { BINANCE_WEB3_WALLET_ID, BINANCE_WEB3_WALLET_NAME } from '.';
import { isMobile } from '@/base/utils/mobile';

export type BinanceWeb3WalletConnectorOptions = Required<
ConstructorParameters<typeof InjectedConnector>
>[0]['options'];

export interface CustomConstructorParams {
chains?: Chain[];
options?: BinanceWeb3WalletConnectorOptions;
}

export class BinanceWeb3WalletConnector extends InjectedConnector {
public id = BINANCE_WEB3_WALLET_ID;
protected shimDisconnectKey = `${this.id}.shimDisconnect`;

constructor(props: CustomConstructorParams) {
const { chains, options: _options } = props ?? {};

const options = {
name: BINANCE_WEB3_WALLET_NAME,
shimDisconnect: true,
getProvider,
..._options,
};

if (typeof window !== 'undefined') {
(window.ethereum as any)?.enable?.();
}

super({
chains,
options,
});
}

public async getProvider() {
await sleep();
return this.options.getProvider();
}
}

function getProvider() {
if (typeof window === 'undefined') return;

if (isMobile()) {
return window.ethereum;
}
}
17 changes: 4 additions & 13 deletions packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Chain } from 'wagmi';
import { PartialCustomProps, WalletProps } from '..';
import { CustomConnector } from '../custom/connector';
import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon';
import { isMobile } from '@/base/utils/mobile';
import { hasInjectedProvider } from '../utils';
import { BinanceWeb3WalletConnector } from './connector';

export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet';
export const BINANCE_WEB3_WALLET_NAME = 'Binance Web3 Wallet';

export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
const { connectorOptions, ...restProps } = props;

return {
id: BINANCE_WEB3_WALLET_ID,
name: 'Binance Web3 Wallet',
name: BINANCE_WEB3_WALLET_NAME,
logos: {
default: <BinanceWeb3WalletIcon />,
transparent: <BinanceWeb3WalletTransparentIcon />,
Expand All @@ -24,19 +24,10 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
showQRCode: true,
isInstalled: isBinanceWeb3Wallet,
createConnector: (chains: Chain[]) => {
return new CustomConnector({
id: BINANCE_WEB3_WALLET_ID,
return new BinanceWeb3WalletConnector({
chains,
options: {
name: 'Binance Web3 Wallet',
shimDisconnect: true,
getProvider() {
if (typeof window === 'undefined') return;

if (isMobile()) {
return window.ethereum;
}
},
...connectorOptions,
},
});
Expand Down
4 changes: 4 additions & 0 deletions packages/walletkit/src/wallets/custom/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ export class CustomConnector extends InjectedConnector {
this.id = id;
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
}

public async getProvider() {
return this.options.getProvider();
}
}
4 changes: 0 additions & 4 deletions website/.env.example

This file was deleted.

2 changes: 1 addition & 1 deletion website/src/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const config = createConfig(
getDefaultConfig({
appName: 'WalletKit',
chains,
autoConnect: false,
autoConnect: true,
connectors: [
binanceWeb3Wallet(),
bitgetWallet(),
Expand Down

0 comments on commit b11c309

Please sign in to comment.