Skip to content

Commit

Permalink
alpha adapter test
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Sep 13, 2022
1 parent af2257a commit f731ea1
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/wallets/alpha/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EventEmitter, SendTransactionOptions, WalletName } from '@solana/wallet-adapter-base';
import {
BaseMessageSignerWalletAdapter,
isVersionedTransaction,
scopePollingDetectionStrategy,
WalletAccountError,
WalletConnectionError,
Expand Down Expand Up @@ -49,10 +50,11 @@ export interface AlphaWalletAdapterConfig {}
export const AlphaWalletName = 'Alpha' as WalletName<'Alpha'>;

export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
name = AlphaWalletName;
url = 'https://github.com/babilu-online/alpha-wallet';
icon =
readonly name = AlphaWalletName;
readonly url = 'https://github.com/babilu-online/alpha-wallet';
readonly icon =
'data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACxEAAAsRAX9kX5EAAAbrSURBVHhe7ZprbBRVFMfvvPru0paG1pZSim2gEkwQFUsIaqMQEkWpVgMRLSDSRB4tNSZ8kC8aE4w8pCCrJgjBaDQaXiHR8MEgMRGJEtRk01IeBsEaVlQKtNDdGf937l3a3bkz7IuZGvcXztxzZi/dOeeeuffcmSUZMmTIkCHD/xeJt2mjq6vLt+b6ie6D2qV8fiqW3yGTSX3rIDO9ReZt2hgcHFzaEq4sQ2QLYIqkDvIUZESQ1gD0nDypypK0eqJcSO4P+/hZIW289Zy0BkDXjWZJlqtlWSaL9Ap+Vsh0EvDP4LqnpDUAsiJ3UOepzCIlpMbI5Z8IGRFZkLYAnD1zphGOT4sEQIE855wF85EF1Vz3jLQFQFGUDuq0GQCFtfPIGFJENN7DggpZyVTvSEsALpw/PxkBmBsZ/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1PJ/2QagThIjMF/LT1XmKQYwgApnpcOnaiw5mg+Vaerl24lZtx4XQLLIa45TyFvkhczlQbQno70ZHdBpXoVw05khJsGTVxJzfjRpgBGH1a+HRDJpgn3IP+eKIGWXCdmcM43llFQuFTSH2NKDQDuPAsKFfz3uite/4100gAuwygDzPddp5yB+RZpsZwY3AFRl8jOkZ+uOCfKsn9Dbll9HFbwtgFoIO3XmB9bX68swDpv4w5PMx509aJT9Y+2jN2Ti/vnRCWACD9Z6J5gFmeMBXXEL3DuzawGKNfPOQ0c5zOB1jw9BqlIOlS3DIH4MtfRvMIsyzgm83iJx3MhYxhqgW6tX7S1H55VyHBy1240jvNe95cAYakQM3af2VK6xNm3yQQToJugEC/imY9syzQQmYigtBDDq9vIoOhL4Y7bQoPBAqfWefuXnrr+sEG/BXP+ABit12l17XK1G6E2i33PZdsQzqaivMUzwKA0aUPLJy2rC0zftw9G6M/03TYMvkZJEeX3uZ9k8bLDKBsgdjV7YWN+ZWfRjvNiyBMfqpunGqUSh2f98WDpwFAFtBi6yCzrLxYNbVIpdMUrf5MGRp9VSeb9ty3wPF5Xzx4nQEU2zdF1blFpKlskiX9Jd34s1RXEy57RYyEAHwNOcFUK20TGm6OeiQQim5s/+3Btqu8S0p4HgDcBvDKPgsaSqrI9KLKoQwwjAFNlxLa8TkxEjKA8gnEtpRtj2SBWfkZu/sfXUt/6ZEWRkQAkAV092f58UKEporJZFyOjwZBlw1PnkDfflAZjoH0Q4Ss7z5ikH3rnN4B/veBn52QXpEEr1/trT600ek1WIYMGTJkyJAhEQj5Fz7jUetUp2rXAAAAAElFTkSuQmCC';
readonly supportedTransactionVersions = null;

private _connecting: boolean;
private _wallet: AlphaWallet | null;
Expand Down Expand Up @@ -164,9 +166,8 @@ export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

if ('message' in transaction) {
if (isVersionedTransaction(transaction))
throw new WalletSendTransactionError(`Sending versioned transactions isn't supported by this wallet`);
}

try {
const { signers, ...sendOptions } = options;
Expand All @@ -189,13 +190,16 @@ export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

if (isVersionedTransaction(transaction))
throw new WalletSendTransactionError(`Signing versioned transactions isn't supported by this wallet`);

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) || transaction) as T;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
Expand All @@ -205,13 +209,20 @@ export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

for (const transaction of transactions) {
if (isVersionedTransaction(transaction))
throw new WalletSendTransactionError(
`Signing versioned transactions isn't supported by this wallet`
);
}

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions as Transaction[])) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
Expand Down

0 comments on commit f731ea1

Please sign in to comment.