Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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()],
},
]
50 changes: 26 additions & 24 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 @@ -42,22 +41,26 @@ export class WalletPluginWombat extends AbstractWalletPlugin implements WalletPl
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)
}
}