Skip to content

Commit 25d02ec

Browse files
committed
enhancement: making the plugin useable in ssr
1 parent ef28220 commit 25d02ec

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

rollup.config.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import commonjs from '@rollup/plugin-commonjs'
55
import nodePolyfills from 'rollup-plugin-polyfill-node'
66
import resolve from '@rollup/plugin-node-resolve'
77
import json from '@rollup/plugin-json'
8-
98
import {createRequire} from 'module'
109
const require = createRequire(import.meta.url)
1110
const pkg = require('./package.json')
@@ -30,7 +29,7 @@ export default [
3029
input: 'src/index.ts',
3130
output: {
3231
banner,
33-
file: pkg.main,
32+
dir: pkg.main,
3433
format: 'cjs',
3534
sourcemap: true,
3635
exports: 'named',
@@ -50,7 +49,7 @@ export default [
5049
input: 'src/index.ts',
5150
output: {
5251
banner,
53-
file: pkg.module,
52+
dir: pkg.module,
5453
format: 'esm',
5554
sourcemap: true,
5655
},
@@ -67,7 +66,7 @@ export default [
6766
},
6867
{
6968
input: 'src/index.ts',
70-
output: {banner, file: pkg.types, format: 'esm'},
69+
output: {banner, dir: pkg.types, format: 'esm'},
7170
plugins: [dts()],
7271
},
7372
]

src/index.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
WalletPluginMetadata,
1111
WalletPluginSignResponse,
1212
} from '@wharfkit/session'
13-
import {handleLogin, handleLogout, handleSignatureRequest} from '@wharfkit/protocol-scatter'
1413

1514
export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPlugin {
1615
id = 'wombat'
@@ -38,26 +37,30 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
3837
readonly metadata: WalletPluginMetadata = WalletPluginMetadata.from({
3938
name: 'Wombat',
4039
description: '',
41-
logo: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/x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gdO2UPU+gd7RXsONakvP8wjDKJNKJB80Rh4j3jBHzuhAHzLQMwIkcEquln2kjEQKmcj9oy90t/lG9pp1o79LHNMpmyZ/gsi5ASPmJ0bkp0DPiOmyFszIGkOB/lDJj8MsCmSdBv2hW90bupW+YdcH6bE344qZYGtLM6qaTvr+Q0bkFoH/Hv1I/cRUtGVG2cPoUJXuIGIwclW5mQI5p/QGUXtvEN0/ELrvWWT/oQAWvrxrzL5VF39797eTyeVIJhMLndPvq+q1QDNisG3PYtc8PuZwCSOkjJAwghWKHx04lEiHXFEzoeo/I2XVobx7szVpdGbbh1XpV1MVe+DQIfL5gIRnvVwYnauqNytcJn3drfbpX2K2vAFGxhxWiJsc+XpCcUq/wr+Bp61IW6Q6YEWY0barKr1qBilap72dMIxIJpN+EASnO2Mvl93vL7F/ffJUeXdTM/lcpQMwJf4u5QNgvcCLRuStSHXQEwGU1iotcUwgEGcA+w50EEUhmcjRcOKcBn3r9fl2zROLeO/tkzXIzxVo0viduUhckvYDu4k/qtkuIjs682HXFN9iBRIiTH2peiscLVUcaYwyA0ctt13dPaQPdw2Qy2x1PYe3avch5iw4id7Ow14ucjZyKglronrPRB3Z0PlGijM4LeHRWoMLTbhFxpKOlUuQ/bvwVMk7R+SUhDUYASNC04s7J/yZ/wfCGAz5/r8LngAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0xMC0wNVQxMDowODoyNSswMDowMKM3wHoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMTAtMDVUMTA6MDg6MjUrMDA6MDDSanjGAAAAAElFTkSuQmCC',
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

Comments
 (0)