2022-05-03 21:20:14 -07:00
|
|
|
import { Wallet } from '@project-serum/anchor'
|
2022-07-21 22:09:04 -07:00
|
|
|
import { Wallet as WalletAdapter } from '@solana/wallet-adapter-react'
|
2022-05-03 21:20:14 -07:00
|
|
|
import { Keypair, PublicKey, Transaction } from '@solana/web3.js'
|
2022-07-21 22:09:04 -07:00
|
|
|
import { notify } from './notifications'
|
2022-05-03 21:20:14 -07:00
|
|
|
|
|
|
|
export default class EmptyWallet implements Wallet {
|
|
|
|
constructor(readonly payer: Keypair) {}
|
|
|
|
|
|
|
|
async signTransaction(tx: Transaction): Promise<Transaction> {
|
|
|
|
tx.partialSign(this.payer)
|
|
|
|
return tx
|
|
|
|
}
|
|
|
|
|
|
|
|
async signAllTransactions(txs: Transaction[]): Promise<Transaction[]> {
|
|
|
|
return txs.map((t) => {
|
|
|
|
t.partialSign(this.payer)
|
|
|
|
return t
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
get publicKey(): PublicKey {
|
|
|
|
return this.payer.publicKey
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 22:09:04 -07:00
|
|
|
|
|
|
|
export const handleWalletConnect = (wallet: WalletAdapter) => {
|
|
|
|
if (!wallet) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
wallet?.adapter?.connect().catch((e) => {
|
|
|
|
if (e.name.includes('WalletLoadError')) {
|
|
|
|
notify({
|
|
|
|
title: `${wallet.adapter.name} Error`,
|
|
|
|
type: 'error',
|
|
|
|
description: `Please install ${wallet.adapter.name} and then reload this page.`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|