Merge pull request #146 from vsakos/main
Solflare SDK with the unified adapter
This commit is contained in:
commit
4444ad996b
|
@ -31,6 +31,7 @@
|
|||
"@sentry/nextjs": "^6.17.4",
|
||||
"@solana/web3.js": "^1.31.0",
|
||||
"@solflare-wallet/pfp": "^0.0.6",
|
||||
"@solflare-wallet/sdk": "^1.0.10",
|
||||
"@tippyjs/react": "^4.2.5",
|
||||
"big.js": "^6.1.1",
|
||||
"bn.js": "^5.2.0",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { PhantomWalletAdapter } from './phantom'
|
||||
import { SolflareExtensionWalletAdapter } from './solflare-extension'
|
||||
import { SolflareWalletAdapter } from './solflare'
|
||||
import { SolletExtensionAdapter } from './sollet-extension'
|
||||
import { SlopeWalletAdapter } from './slope'
|
||||
import { BitpieWalletAdapter } from './bitpie'
|
||||
|
@ -18,7 +18,7 @@ export const WALLET_PROVIDERS = [
|
|||
name: 'Solflare',
|
||||
url: 'https://solflare.com',
|
||||
icon: `${ASSET_URL}/solflare.svg`,
|
||||
adapter: SolflareExtensionWalletAdapter,
|
||||
adapter: SolflareWalletAdapter,
|
||||
},
|
||||
{
|
||||
name: 'Sollet.io',
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
import EventEmitter from 'eventemitter3'
|
||||
import { PublicKey, Transaction } from '@solana/web3.js'
|
||||
import { notify } from '../../utils/notifications'
|
||||
import { DEFAULT_PUBLIC_KEY, WalletAdapter } from '../../@types/types'
|
||||
|
||||
type SolflareExtensionEvent = 'disconnect' | 'connect'
|
||||
type SolflareExtensionRequestMethod =
|
||||
| 'connect'
|
||||
| 'disconnect'
|
||||
| 'signTransaction'
|
||||
| 'signAllTransactions'
|
||||
|
||||
interface SolflareExtensionProvider {
|
||||
publicKey?: PublicKey
|
||||
isConnected?: boolean
|
||||
autoApprove?: boolean
|
||||
signTransaction: (transaction: Transaction) => Promise<Transaction>
|
||||
signAllTransactions: (transactions: Transaction[]) => Promise<Transaction[]>
|
||||
connect: () => Promise<void>
|
||||
disconnect: () => Promise<void>
|
||||
on: (event: SolflareExtensionEvent, handler: (args: any) => void) => void
|
||||
off: (event: SolflareExtensionEvent, handler: (args: any) => void) => void
|
||||
request: (method: SolflareExtensionRequestMethod, params: any) => Promise<any>
|
||||
}
|
||||
|
||||
export class SolflareExtensionWalletAdapter
|
||||
extends EventEmitter
|
||||
implements WalletAdapter
|
||||
{
|
||||
constructor() {
|
||||
super()
|
||||
this.connect = this.connect.bind(this)
|
||||
}
|
||||
|
||||
private get _provider(): SolflareExtensionProvider | undefined {
|
||||
if ((window as any)?.solflare?.isSolflare) {
|
||||
return (window as any).solflare
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
private _handleConnect = (...args) => {
|
||||
this.emit('connect', ...args)
|
||||
}
|
||||
|
||||
private _handleDisconnect = (...args) => {
|
||||
this._provider?.off('connect', this._handleConnect)
|
||||
this._provider?.off('disconnect', this._handleDisconnect)
|
||||
this.emit('disconnect', ...args)
|
||||
}
|
||||
|
||||
get connected() {
|
||||
return this._provider?.isConnected || false
|
||||
}
|
||||
|
||||
get autoApprove() {
|
||||
return this._provider?.autoApprove || false
|
||||
}
|
||||
|
||||
async signAllTransactions(
|
||||
transactions: Transaction[]
|
||||
): Promise<Transaction[]> {
|
||||
if (!this._provider) {
|
||||
return transactions
|
||||
}
|
||||
|
||||
return this._provider.signAllTransactions(transactions)
|
||||
}
|
||||
|
||||
get publicKey() {
|
||||
const instance = this._provider?.publicKey
|
||||
|
||||
if (instance) {
|
||||
return new PublicKey(instance.toString())
|
||||
}
|
||||
|
||||
return DEFAULT_PUBLIC_KEY
|
||||
}
|
||||
|
||||
async signTransaction(transaction: Transaction) {
|
||||
if (!this._provider) {
|
||||
return transaction
|
||||
}
|
||||
|
||||
return this._provider.signTransaction(transaction)
|
||||
}
|
||||
|
||||
async connect() {
|
||||
if (!this._provider) {
|
||||
notify({
|
||||
title: 'Solflare Extension Error',
|
||||
type: 'error',
|
||||
description:
|
||||
'Please install the Solflare Extension and then reload this page.',
|
||||
})
|
||||
return
|
||||
}
|
||||
this._provider?.on('connect', this._handleConnect)
|
||||
this._provider?.on('disconnect', this._handleDisconnect)
|
||||
return this._provider?.connect()
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
if (this._provider) {
|
||||
this._provider.disconnect()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import Solflare from '@solflare-wallet/sdk'
|
||||
|
||||
export function SolflareWalletAdapter(_, network) {
|
||||
return new Solflare({ network })
|
||||
}
|
10
yarn.lock
10
yarn.lock
|
@ -2215,6 +2215,16 @@
|
|||
cross-fetch "^3.1.4"
|
||||
jdenticon "^3.1.1"
|
||||
|
||||
"@solflare-wallet/sdk@^1.0.10":
|
||||
version "1.0.10"
|
||||
resolved "https://registry.yarnpkg.com/@solflare-wallet/sdk/-/sdk-1.0.10.tgz#336e57f5987431a40b7e9308635153a61a8b8d94"
|
||||
integrity sha512-ym9PbKgozXUP8VYzqM1NKJp6x/HR4aI9YY0GMPqjhezCVuQ9dctp6zZ2RSMnjdh7evcYKgPdp6XgI36yhR3w6w==
|
||||
dependencies:
|
||||
"@project-serum/sol-wallet-adapter" "0.2.0"
|
||||
bs58 "^4.0.1"
|
||||
eventemitter3 "^4.0.7"
|
||||
uuid "^8.3.2"
|
||||
|
||||
"@svgr/babel-plugin-add-jsx-attribute@^6.0.0":
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-6.0.0.tgz#bd6d1ff32a31b82b601e73672a789cc41e84fe18"
|
||||
|
|
Loading…
Reference in New Issue