import { MessageSignerWalletAdapter , SignerWalletAdapter , WalletNotConnectedError } from '@solana/wallet-adapter-base' ; import { Transaction } from '@solana/web3.js' ; import { defer , from , Observable , Subject , throwError } from 'rxjs' ; export const signMessage = ( adapter , connected , errorSubject ) : ( ( message : Uint8Array ) => Observable < Uint8Array > ) => { return ( message ) => { if ( ! connected ) { const error = new WalletNotConnectedError ( ) ; errorSubject . next ( error ) ; return throwError ( error ) ; } return from ( defer ( ( ) => adapter . signMessage ( message ) ) ) ; } ; } ; export const signTransaction = ( adapter , connected , errorSubject ) : ( ( transaction : Transaction ) => Observable < Transaction > ) => { return ( transaction ) => { if ( ! connected ) { const error = new WalletNotConnectedError ( ) ; errorSubject . next ( error ) ; return throwError ( error ) ; } return from ( defer ( ( ) => adapter . signTransaction ( transaction ) ) ) ; } ; } ; export const signAllTransactions = ( adapter , connected , errorSubject ) : ( ( transactions : Transaction [ ] ) => Observable < Transaction [ ] > ) => { return ( transactions ) => { if ( ! connected ) { const error = new WalletNotConnectedError ( ) ; errorSubject . next ( error ) ; return throwError ( error ) ; } return from ( defer ( ( ) => adapter . signAllTransactions ( transactions ) ) ) ; } ; } ;