Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BitKeep Wallet #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/utils/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PhantomWalletAdapter,
SolletExtensionAdapter,
MathWalletAdapter,
BitKeepWalletAdapter,
SolflareExtensionWalletAdapter,
} from '../wallet-adapters';

Expand Down Expand Up @@ -63,6 +64,12 @@ export const WALLET_PROVIDERS = [
icon: `${ASSET_URL}/mathwallet.svg`,
adapter: MathWalletAdapter,
},
{
name: 'BitKeep',
url: 'https://bitkeep.com',
icon: `${ASSET_URL}/bitkeep.svg`,
adapter: BitKeepWalletAdapter,
},
];

const WalletContext = React.createContext<null | WalletContextValues>(null);
Expand Down
91 changes: 91 additions & 0 deletions src/wallet-adapters/bitkeep/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import EventEmitter from 'eventemitter3';
import { PublicKey, Transaction } from '@solana/web3.js';
import { notify } from '../../utils/notifications';
import { DEFAULT_PUBLIC_KEY, WalletAdapter } from '../types';

export class BitKeepWalletAdapter extends EventEmitter implements WalletAdapter {
_publicKey?: PublicKey;
_onProcess: boolean;
_connected: boolean;
constructor() {
super();
this._onProcess = false;
this._connected = false;
this.connect = this.connect.bind(this);
}

get connected() {
return this._connected;
}

get autoApprove() {
return false;
}

public async signAllTransactions(
transactions: Transaction[],
): Promise<Transaction[]> {
if (!this._provider) {
return transactions;
}

return this._provider.signAllTransactions(transactions);
}

private get _provider() {
if ((window as any)?.solana?.isBitKeep) {
return (window as any).solana;
}
return undefined;
}

get publicKey() {
return this._publicKey || DEFAULT_PUBLIC_KEY;
}

async signTransaction(transaction: Transaction) {
if (!this._provider) {
return transaction;
}

return this._provider.signTransaction(transaction);
}

connect() {
if (this._onProcess) {
return;
}

if (!this._provider) {
window.open('https://bitkeep.com/', '_blank');
notify({
message: 'BitKeep Wallet Error',
description: 'Please install BitKeep Wallet',
});
return;
}

this._onProcess = true;
this._provider
.getAccount()
.then((account: any) => {
this._publicKey = new PublicKey(account);
this._connected = true;
this.emit('connect', this._publicKey);
})
.catch(() => {
this.disconnect();
})
.finally(() => {
this._onProcess = false;
});
}

disconnect() {
if (this._publicKey) {
this._publicKey = undefined;
this._connected = false;
this.emit('disconnect');
}
}
}
1 change: 1 addition & 0 deletions src/wallet-adapters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './ledger';
export * from './phantom';
export * from './sollet-extension';
export * from './math';
export * from './bitkeep';
export * from './types';
export * from './solflare-extension';