@@ -10,7 +10,6 @@ import {
1010 WalletPluginMetadata ,
1111 WalletPluginSignResponse ,
1212} from '@wharfkit/session'
13- import { handleLogin , handleLogout , handleSignatureRequest } from '@wharfkit/protocol-scatter'
1413
1514export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPlugin {
1615 id = 'wombat'
@@ -42,22 +41,26 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
4241 homepage : 'https://www.wombat.app/' ,
4342 download : 'https://www.wombat.app/the-app' ,
4443 } )
44+
45+ private async loadScatterProtocol ( ) {
46+ if ( typeof window !== 'undefined' ) {
47+ return import ( '@wharfkit/protocol-scatter' )
48+ }
49+ return null
50+ }
51+
4552 /**
4653 * Performs the wallet logic required to login and return the chain and permission level to use.
4754 *
4855 * @param context LoginContext
4956 * @returns Promise<WalletPluginLoginResponse>
5057 */
51- login ( context : LoginContext ) : Promise < WalletPluginLoginResponse > {
52- return new Promise ( ( resolve , reject ) => {
53- handleLogin ( context )
54- . then ( ( response ) => {
55- resolve ( response )
56- } )
57- . catch ( ( error ) => {
58- reject ( error )
59- } )
60- } )
58+ async login ( context : LoginContext ) : Promise < WalletPluginLoginResponse > {
59+ const scatterProtocol = await this . loadScatterProtocol ( )
60+ if ( ! scatterProtocol ) {
61+ throw new Error ( 'Scatter protocol is not available in this environment' )
62+ }
63+ return scatterProtocol . handleLogin ( context )
6164 }
6265
6366 /**
@@ -66,17 +69,12 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
6669 * @param context: LogoutContext
6770 * @returns Promise<void>
6871 */
69-
70- logout ( context : LogoutContext ) : Promise < void > {
71- return new Promise ( ( resolve , reject ) => {
72- handleLogout ( context )
73- . then ( ( ) => {
74- resolve ( )
75- } )
76- . catch ( ( error ) => {
77- reject ( error )
78- } )
79- } )
72+ async logout ( context : LogoutContext ) : Promise < void > {
73+ const scatterProtocol = await this . loadScatterProtocol ( )
74+ if ( ! scatterProtocol ) {
75+ throw new Error ( 'Scatter protocol is not available in this environment' )
76+ }
77+ return scatterProtocol . handleLogout ( context )
8078 }
8179
8280 /**
@@ -86,10 +84,14 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
8684 * @param resolved ResolvedSigningRequest
8785 * @returns Promise<Signature>
8886 */
89- sign (
87+ async sign (
9088 resolved : ResolvedSigningRequest ,
9189 context : TransactContext
9290 ) : Promise < WalletPluginSignResponse > {
93- return handleSignatureRequest ( resolved , context )
91+ const scatterProtocol = await this . loadScatterProtocol ( )
92+ if ( ! scatterProtocol ) {
93+ throw new Error ( 'Scatter protocol is not available in this environment' )
94+ }
95+ return scatterProtocol . handleSignatureRequest ( resolved , context )
9496 }
9597}
0 commit comments