|
@@ -1,18 +1,22 @@
|
|
|
|
|
+import type { FractalWalletAdapterImpl as FractalWallet } from '@fractalwagmi/solana-wallet-adapter';
|
|
|
|
|
+import type { WalletName } from '@solana/wallet-adapter-base';
|
|
|
import {
|
|
import {
|
|
|
BaseSignerWalletAdapter,
|
|
BaseSignerWalletAdapter,
|
|
|
|
|
+ WalletAccountError,
|
|
|
WalletConfigError,
|
|
WalletConfigError,
|
|
|
WalletConnectionError,
|
|
WalletConnectionError,
|
|
|
WalletDisconnectionError,
|
|
WalletDisconnectionError,
|
|
|
WalletLoadError,
|
|
WalletLoadError,
|
|
|
WalletNotConnectedError,
|
|
WalletNotConnectedError,
|
|
|
WalletNotReadyError,
|
|
WalletNotReadyError,
|
|
|
|
|
+ WalletPublicKeyError,
|
|
|
WalletReadyState,
|
|
WalletReadyState,
|
|
|
WalletSignTransactionError,
|
|
WalletSignTransactionError,
|
|
|
} from '@solana/wallet-adapter-base';
|
|
} from '@solana/wallet-adapter-base';
|
|
|
-import type { WalletName } from '@solana/wallet-adapter-base';
|
|
|
|
|
import type { Transaction } from '@solana/web3.js';
|
|
import type { Transaction } from '@solana/web3.js';
|
|
|
-import type { PublicKey } from '@solana/web3.js';
|
|
|
|
|
-import type { FractalWalletAdapterImpl as FractalWallet } from '@fractalwagmi/solana-wallet-adapter';
|
|
|
|
|
|
|
+import { PublicKey } from '@solana/web3.js';
|
|
|
|
|
+
|
|
|
|
|
+export interface FractalWalletAdapterConfig {}
|
|
|
|
|
|
|
|
export const FractalWalletName = 'Fractal' as WalletName<'Fractal'>;
|
|
export const FractalWalletName = 'Fractal' as WalletName<'Fractal'>;
|
|
|
|
|
|
|
@@ -21,19 +25,17 @@ export class FractalWalletAdapter extends BaseSignerWalletAdapter {
|
|
|
url = 'https://developers.fractal.is/wallet-adapters/solana';
|
|
url = 'https://developers.fractal.is/wallet-adapters/solana';
|
|
|
icon =
|
|
icon =
|
|
|
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiPjxwYXRoIGQ9Ik0zNDIuMjQgNzYzLjkzVjI0My44Mkg3MTV2MTEyLjY5SDQ4MXYxMTUuNThoMTgydjExMi42OUg0ODF2MTc5LjE1WiIgc3R5bGU9ImZpbGw6I2RlMzU5YyIvPjwvc3ZnPg==';
|
|
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiPjxwYXRoIGQ9Ik0zNDIuMjQgNzYzLjkzVjI0My44Mkg3MTV2MTEyLjY5SDQ4MXYxMTUuNThoMTgydjExMi42OUg0ODF2MTc5LjE1WiIgc3R5bGU9ImZpbGw6I2RlMzU5YyIvPjwvc3ZnPg==';
|
|
|
-
|
|
|
|
|
readonly supportedTransactionVersions = null;
|
|
readonly supportedTransactionVersions = null;
|
|
|
|
|
|
|
|
- private readonly _readyState: WalletReadyState =
|
|
|
|
|
- typeof window === 'undefined' || typeof document === 'undefined'
|
|
|
|
|
- ? WalletReadyState.Unsupported
|
|
|
|
|
- : WalletReadyState.Loadable;
|
|
|
|
|
-
|
|
|
|
|
private _connecting: boolean;
|
|
private _connecting: boolean;
|
|
|
private _wallet: FractalWallet | null;
|
|
private _wallet: FractalWallet | null;
|
|
|
private _publicKey: PublicKey | null;
|
|
private _publicKey: PublicKey | null;
|
|
|
|
|
+ private _readyState: WalletReadyState =
|
|
|
|
|
+ typeof window === 'undefined' || typeof document === 'undefined'
|
|
|
|
|
+ ? WalletReadyState.Unsupported
|
|
|
|
|
+ : WalletReadyState.Loadable;
|
|
|
|
|
|
|
|
- constructor() {
|
|
|
|
|
|
|
+ constructor(config: FractalWalletAdapterConfig = {}) {
|
|
|
super();
|
|
super();
|
|
|
this._connecting = false;
|
|
this._connecting = false;
|
|
|
this._wallet = null;
|
|
this._wallet = null;
|
|
@@ -41,17 +43,13 @@ export class FractalWalletAdapter extends BaseSignerWalletAdapter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
get publicKey() {
|
|
get publicKey() {
|
|
|
- return this._wallet?.getPublicKey() ?? null;
|
|
|
|
|
|
|
+ return this._publicKey;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
get connecting() {
|
|
get connecting() {
|
|
|
return this._connecting;
|
|
return this._connecting;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- get connected() {
|
|
|
|
|
- return !!this.publicKey;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
get readyState() {
|
|
get readyState() {
|
|
|
return this._readyState;
|
|
return this._readyState;
|
|
|
}
|
|
}
|
|
@@ -77,7 +75,8 @@ export class FractalWalletAdapter extends BaseSignerWalletAdapter {
|
|
|
throw new WalletConfigError(error?.message, error);
|
|
throw new WalletConfigError(error?.message, error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!wallet.getPublicKey()) {
|
|
|
|
|
|
|
+ const account = wallet.getPublicKey();
|
|
|
|
|
+ if (!account) {
|
|
|
try {
|
|
try {
|
|
|
await wallet.connect();
|
|
await wallet.connect();
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
@@ -85,13 +84,18 @@ export class FractalWalletAdapter extends BaseSignerWalletAdapter {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this._wallet = wallet;
|
|
|
|
|
- this._publicKey = wallet.getPublicKey();
|
|
|
|
|
- if (!this._publicKey) {
|
|
|
|
|
- throw new WalletConnectionError('Expected a public key');
|
|
|
|
|
|
|
+ let publicKey: PublicKey;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
+ publicKey = new PublicKey(wallet.getPublicKey()!.toBytes());
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ throw new WalletPublicKeyError(error?.message, error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.emit('connect', this._publicKey);
|
|
|
|
|
|
|
+ this._wallet = wallet;
|
|
|
|
|
+ this._publicKey = publicKey;
|
|
|
|
|
+
|
|
|
|
|
+ this.emit('connect', publicKey);
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
this.emit('error', error);
|
|
this.emit('error', error);
|
|
|
throw error;
|
|
throw error;
|
|
@@ -102,7 +106,6 @@ export class FractalWalletAdapter extends BaseSignerWalletAdapter {
|
|
|
|
|
|
|
|
async disconnect(): Promise<void> {
|
|
async disconnect(): Promise<void> {
|
|
|
const wallet = this._wallet;
|
|
const wallet = this._wallet;
|
|
|
-
|
|
|
|
|
if (wallet) {
|
|
if (wallet) {
|
|
|
this._wallet = null;
|
|
this._wallet = null;
|
|
|
this._publicKey = null;
|
|
this._publicKey = null;
|