add bitpie wallet (#86)
This commit is contained in:
parent
9bc1d16dc4
commit
36f6585b6a
|
@ -8,6 +8,7 @@ import {
|
||||||
SlopeWalletAdapter,
|
SlopeWalletAdapter,
|
||||||
SolletExtensionAdapter,
|
SolletExtensionAdapter,
|
||||||
SolflareExtensionWalletAdapter,
|
SolflareExtensionWalletAdapter,
|
||||||
|
BitpieWalletAdapter,
|
||||||
} from '../utils/wallet-adapters'
|
} from '../utils/wallet-adapters'
|
||||||
import { WalletAdapter } from '../@types/types'
|
import { WalletAdapter } from '../@types/types'
|
||||||
import useInterval from './useInterval'
|
import useInterval from './useInterval'
|
||||||
|
@ -47,6 +48,12 @@ export const WALLET_PROVIDERS = [
|
||||||
icon: 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHdpZHRoPSIxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iNjQiIGN5PSI2NCIgZmlsbD0iIzZlNjZmYSIgcj0iNjQiLz48ZyBmaWxsPSIjZmZmIj48cGF0aCBkPSJtMzUuMTk2MyA1NC4zOTk4aDE5LjJ2MTkuMmgtMTkuMnoiLz48cGF0aCBkPSJtNzMuNTk3IDU0LjM5OTgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMnoiIGZpbGwtb3BhY2l0eT0iLjQiLz48cGF0aCBkPSJtNzMuNTk3IDczLjU5OTgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMnoiIGZpbGwtb3BhY2l0eT0iLjc1Ii8+PHBhdGggZD0ibTczLjYwNCA1NC4zOTk4aDE5LjJ2MTkuMmgtMTkuMnoiLz48cGF0aCBkPSJtNTQuMzk2OCAzNS4yIDE5LjItMTkuMnYxOS4ybC0xOS4yIDE5LjJoLTE5LjJ6IiBmaWxsLW9wYWNpdHk9Ii43NSIvPjxwYXRoIGQ9Im03My41OTE1IDkyLjgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMmgxOS4yeiIgZmlsbC1vcGFjaXR5PSIuNCIvPjwvZz48L3N2Zz4=',
|
icon: 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHdpZHRoPSIxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iNjQiIGN5PSI2NCIgZmlsbD0iIzZlNjZmYSIgcj0iNjQiLz48ZyBmaWxsPSIjZmZmIj48cGF0aCBkPSJtMzUuMTk2MyA1NC4zOTk4aDE5LjJ2MTkuMmgtMTkuMnoiLz48cGF0aCBkPSJtNzMuNTk3IDU0LjM5OTgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMnoiIGZpbGwtb3BhY2l0eT0iLjQiLz48cGF0aCBkPSJtNzMuNTk3IDczLjU5OTgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMnoiIGZpbGwtb3BhY2l0eT0iLjc1Ii8+PHBhdGggZD0ibTczLjYwNCA1NC4zOTk4aDE5LjJ2MTkuMmgtMTkuMnoiLz48cGF0aCBkPSJtNTQuMzk2OCAzNS4yIDE5LjItMTkuMnYxOS4ybC0xOS4yIDE5LjJoLTE5LjJ6IiBmaWxsLW9wYWNpdHk9Ii43NSIvPjxwYXRoIGQ9Im03My41OTE1IDkyLjgtMTkuMiAxOS4ydi0xOS4ybDE5LjItMTkuMmgxOS4yeiIgZmlsbC1vcGFjaXR5PSIuNCIvPjwvZz48L3N2Zz4=',
|
||||||
adapter: SlopeWalletAdapter,
|
adapter: SlopeWalletAdapter,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Bitpie',
|
||||||
|
url: 'https://bitpie.com',
|
||||||
|
icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz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4MTgxODIsNDYuMzcxOTQ0NSA0MC41NTM3NjI3LDQ4IDM4LjU0NTQ1NDUsNDggQzM2LjUzNzE0NjQsNDggMzQuOTA5MDkwOSw0Ni4zNzE5NDQ1IDM0LjkwOTA5MDksNDQuMzYzNjM2NCBMMzQuOTA5LDQyLjE4MSBMMjkuMDksNDIuMTgxIEwyOS4wOTA5MDkxLDQ0LjM2MzYzNjQgWiBNMjkuMDksMzQuOTA5IEwzNC45MDksMzQuOTA5IEwzNC45MDksMjkuMDkgTDI5LjA5LDI5LjA5IEwyOS4wOSwzNC45MDkgWiIgaWQ9IkNvbWJpbmVkLVNoYXBlIiBmaWxsPSJ1cmwoI2xpbmVhckdyYWRpZW50LTMpIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgzMi4wMDAwMDAsIDMyLjAwMDAwMCkgcm90YXRlKC0zMC4wMDAwMDApIHRyYW5zbGF0ZSgtMzIuMDAwMDAwLCAtMzIuMDAwMDAwKSAiPjwvcGF0aD4KICAgICAgICA8L2c+CiAgICA8L2c+Cjwvc3ZnPg==',
|
||||||
|
adapter: BitpieWalletAdapter,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
export const PROVIDER_LOCAL_STORAGE_KEY = 'walletProvider-0.1'
|
export const PROVIDER_LOCAL_STORAGE_KEY = 'walletProvider-0.1'
|
||||||
export const DEFAULT_PROVIDER = WALLET_PROVIDERS[0]
|
export const DEFAULT_PROVIDER = WALLET_PROVIDERS[0]
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
import EventEmitter from 'eventemitter3'
|
||||||
|
import { PublicKey, Transaction } from '@solana/web3.js'
|
||||||
|
import { notify } from '../../utils/notifications'
|
||||||
|
import { WalletAdapter } from '../../@types/types'
|
||||||
|
|
||||||
|
interface BitpieWallet {
|
||||||
|
getAccount(): Promise<string>;
|
||||||
|
signTransaction(transaction: Transaction): Promise<Transaction>;
|
||||||
|
signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BitpieWalletWindow extends Window {
|
||||||
|
bitpie?: BitpieWallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare const window: BitpieWalletWindow;
|
||||||
|
|
||||||
|
export class BitpieWalletAdapter extends EventEmitter implements WalletAdapter {
|
||||||
|
private _connecting: boolean;
|
||||||
|
private _wallet: BitpieWallet | null;
|
||||||
|
private _publicKey: PublicKey | null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._connecting = false;
|
||||||
|
this._wallet = null;
|
||||||
|
this._publicKey = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get publicKey(): PublicKey | null {
|
||||||
|
return this._publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
get ready(): boolean {
|
||||||
|
return typeof window !== 'undefined' && !!window.bitpie;
|
||||||
|
}
|
||||||
|
|
||||||
|
get connecting(): boolean {
|
||||||
|
return this._connecting;
|
||||||
|
}
|
||||||
|
|
||||||
|
get connected(): boolean {
|
||||||
|
return !!this._wallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
get autoApprove() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async connect(): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.connected || this.connecting) return;
|
||||||
|
this._connecting = true;
|
||||||
|
|
||||||
|
const wallet = typeof window !== 'undefined' && window.bitpie;
|
||||||
|
if (!wallet) return;
|
||||||
|
|
||||||
|
let account: string;
|
||||||
|
try {
|
||||||
|
account = await wallet.getAccount();
|
||||||
|
} catch (error: any) {
|
||||||
|
notify({
|
||||||
|
title: 'Connection Error',
|
||||||
|
type: 'error',
|
||||||
|
description: 'Please install Bitpie wallet and then reload this page.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this._wallet = wallet;
|
||||||
|
this._publicKey = new PublicKey(account);
|
||||||
|
|
||||||
|
this.emit('connect');
|
||||||
|
} catch (error: any) {
|
||||||
|
this.emit('error', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this._connecting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async disconnect(): Promise<void> {
|
||||||
|
if (this._wallet) {
|
||||||
|
this._wallet = null;
|
||||||
|
this._publicKey = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('disconnect');
|
||||||
|
}
|
||||||
|
|
||||||
|
async signTransaction(transaction: Transaction): Promise<Transaction> {
|
||||||
|
try {
|
||||||
|
const wallet = this._wallet;
|
||||||
|
if (!wallet) return ;
|
||||||
|
|
||||||
|
return (await wallet.signTransaction(transaction)) || transaction;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.emit('error', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
|
||||||
|
try {
|
||||||
|
const wallet = this._wallet;
|
||||||
|
if (!wallet) return ;
|
||||||
|
|
||||||
|
return (await wallet.signAllTransactions(transactions)) || transactions;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.emit('error', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,3 +2,4 @@ export * from './phantom'
|
||||||
export * from './solflare-extension'
|
export * from './solflare-extension'
|
||||||
export * from './sollet-extension'
|
export * from './sollet-extension'
|
||||||
export * from './slope'
|
export * from './slope'
|
||||||
|
export * from './bitpie'
|
||||||
|
|
Loading…
Reference in New Issue