Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Add BitKeep Wallet Provider #333

Open
wants to merge 3 commits into
base: main
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
5 changes: 5 additions & 0 deletions assets/wallets/bitkeep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/common/src/contexts/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TorusWalletAdapter } from '../wallet-adapters/torus';
import { useLocation } from 'react-router';
import { LedgerWalletAdapter } from '@solana/wallet-ledger';
import {MathWalletAdapter} from "../wallet-adapters/mathWallet";
import { BitKeepWalletAdapter } from "../wallet-adapters/bitkeep";

const ASSETS_URL =
'https://raw.githubusercontent.com/solana-labs/oyster/main/assets/wallets/';
Expand Down Expand Up @@ -52,6 +53,12 @@ export const WALLET_PROVIDERS = [
icon: `${ASSETS_URL}mathwallet.svg`,
adapter: MathWalletAdapter,
},
{
name: 'BitKeep',
url: 'https://bitkeep.com',
icon: `${ASSETS_URL}bitkeep.svg`,
adapter: MathWalletAdapter,
},
// {
// name: 'Torus',
// url: 'https://tor.us',
Expand Down
92 changes: 92 additions & 0 deletions packages/common/src/wallet-adapters/bitkeep/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import EventEmitter from 'eventemitter3';
import { PublicKey, Transaction } from '@solana/web3.js';
import { WalletAdapter } from '@solana/wallet-base';
import { notify } from '../../utils/notifications';

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

get publicKey() {
return this._publicKey;
}

get connected() {
return this._connected;
}

get autoApprove() {
return false;
}

// eslint-disable-next-line
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;
}

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

return this._provider.signTransaction(transaction);
}

connect() {
if (this._onProcess) {
return;
}
if (!this._provider) {
notify({
message: 'BitKeep Error',
description:
'Please open it in 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 = null;
this._connected = false;
this.emit('disconnect');
}
}
}