Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the plugin usable in SSR #18

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"version": "1.3.1",
"homepage": "https://github.com/wharfkit/wallet-plugin-wombat",
"license": "BSD-3-Clause",
"main": "lib/wallet-plugin-wombat.js",
"module": "lib/wallet-plugin-wombat.m.js",
"types": "lib/wallet-plugin-wombat.d.ts",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"types": "lib/types/index.d.ts",
"sideEffects": false,
"files": [
"lib/*",
Expand Down
7 changes: 4 additions & 3 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export default [
input: 'src/index.ts',
output: {
banner,
file: pkg.main,
dir: pkg.main.split('/').slice(0, -1).join('/'),
format: 'cjs',
sourcemap: true,
exports: 'named',
inlineDynamicImports: true,
},
plugins: [
typescript({target: 'es6'}),
Expand All @@ -50,7 +51,7 @@ export default [
input: 'src/index.ts',
output: {
banner,
file: pkg.module,
dir: pkg.module.split('/').slice(0, -1).join('/'),
format: 'esm',
sourcemap: true,
},
Expand All @@ -67,7 +68,7 @@ export default [
},
{
input: 'src/index.ts',
output: {banner, file: pkg.types, format: 'esm'},
output: {banner, dir: pkg.types, format: 'esm'},
plugins: [dts()],
},
]
52 changes: 27 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
WalletPluginMetadata,
WalletPluginSignResponse,
} from '@wharfkit/session'
import {handleLogin, handleLogout, handleSignatureRequest} from '@wharfkit/protocol-scatter'

export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPlugin {
id = 'wombat'
Expand Down Expand Up @@ -38,26 +37,30 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
readonly metadata: WalletPluginMetadata = WalletPluginMetadata.from({
name: 'Wombat',
description: '',
logo: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH5goFCggZ0IIdsgAACdVJREFUaN69mmuMXVUVgL+19zn33pnO2Gln2ukLmj5AoCIUNCiRh1Agom0FKSAKyqNRHoIhBJSoqGiMpJGHIAkqSSUkSjXQRmTEQGgREmxaaGMboNJCX9NOO++Z+zrn7OWPc+e2c+fO3HunU1Yyc5Nz9t5nfXuttfda+xxhgsUtW4ACIgKAFK7r0D8BRbFrP5jQ58qxDhAtnY+IQYZGEnBOrYjUA5OAROE5AUoaGBSRoICGFn7NMYKNGyS3bCG+xAOoqiciJwCLgTOBU4A5wBQgVegSAL1AO7ADeAfYrOhOQTIKOFW8deMDqhnELV+AFLopNANfFLgC+HxBeb/aoYAOYDOwVqFNjOzGKaqKqRGoJhBdvmCoSxNwJXAzcDaQHNc0Dod6F3hW4RmBPQqYtf+beBC3fCGoExFzAfAD4CKqn/1a5G1glYO/CeSoEshUBFAlvGspqDaKmHuBvwCXxRB6HDhYDPzewMPAbAGiZQuOHUQABvumizGPAA8C01EHngepetBqYBTU1QJTD9wq8CeFTxkRwgowY4JorORM8+nPPYHqjYCPczBnIdz5EPz4D3D+0goMDhJ1MHMueH6V4EW5SGA1cLYVIbd0/qgNvdFuOOcgXpUeltnzriIKQQRaZsKtPydadA4KeCcshN5O2LwBjC3MPkd+Z82Fb9wNp30G1q+DPz8GYVALzFnAUwo3JIzZNlqjssFegEiJy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6MDDSanjGAAAAAElFTkSuQmCC',
homepage: 'https://www.wombat.app/',
download: 'https://www.wombat.app/the-app',
})

private async loadScatterProtocol() {
if (typeof window !== 'undefined') {
return import('@wharfkit/protocol-scatter')
}
return null
}

/**
* Performs the wallet logic required to login and return the chain and permission level to use.
*
* @param context LoginContext
* @returns Promise<WalletPluginLoginResponse>
*/
login(context: LoginContext): Promise<WalletPluginLoginResponse> {
return new Promise((resolve, reject) => {
handleLogin(context)
.then((response) => {
resolve(response)
})
.catch((error) => {
reject(error)
})
})
async login(context: LoginContext): Promise<WalletPluginLoginResponse> {
const scatterProtocol = await this.loadScatterProtocol()
if (!scatterProtocol) {
throw new Error('Scatter protocol is not available in this environment')
}
return scatterProtocol.handleLogin(context)
}

/**
Expand All @@ -66,17 +69,12 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
* @param context: LogoutContext
* @returns Promise<void>
*/

logout(context: LogoutContext): Promise<void> {
return new Promise((resolve, reject) => {
handleLogout(context)
.then(() => {
resolve()
})
.catch((error) => {
reject(error)
})
})
async logout(context: LogoutContext): Promise<void> {
const scatterProtocol = await this.loadScatterProtocol()
if (!scatterProtocol) {
throw new Error('Scatter protocol is not available in this environment')
}
return scatterProtocol.handleLogout(context)
}

/**
Expand All @@ -86,10 +84,14 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
* @param resolved ResolvedSigningRequest
* @returns Promise<Signature>
*/
sign(
async sign(
resolved: ResolvedSigningRequest,
context: TransactContext
): Promise<WalletPluginSignResponse> {
return handleSignatureRequest(resolved, context)
const scatterProtocol = await this.loadScatterProtocol()
if (!scatterProtocol) {
throw new Error('Scatter protocol is not available in this environment')
}
return scatterProtocol.handleSignatureRequest(resolved, context)
}
}