Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | 34x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import {
AbstractTransactPlugin,
TransactContext,
TransactHookResponseType,
TransactHookTypes,
} from '@wharfkit/session'
/** Import JSON localization strings */
import defaultTranslations from './translations'
export class TransactPluginTemplate extends AbstractTransactPlugin {
/** A unique ID for this plugin */
id = 'transact-plugin-template'
/** Optional - The translation strings to use for the plugin */
translations = defaultTranslations
/**
* Register the hooks required for this plugin to function
*
* @param context The TransactContext of the transaction being performed
*/
register(context: TransactContext): void {
// Optional - Retrieve the translation function from the UI if it exists
let t
Iif (context.ui) {
t = context.ui.getTranslate()
}
// Register any desired beforeSign hooks
context.addHook(
TransactHookTypes.beforeSign,
async (request, context): Promise<TransactHookResponseType> => {
// If this plugin is interacting with the UI, throw an error since this is an undefined function
Iif (context.ui) {
throw new Error(
// Translate the error message against the given key or use the default value as English
t('beforesign', {
default: 'undefined beforeSign hook called from plugin template',
})
)
} else {
// eslint-disable-next-line no-console
console.log('undefined beforeSign hook called with', request, context)
}
return
}
)
// Register any desired afterSign hooks
context.addHook(
TransactHookTypes.afterSign,
async (request, context): Promise<TransactHookResponseType> => {
// If this plugin is interacting with the UI, throw an error since this is an undefined function
Iif (context.ui) {
throw new Error(
// Translate the error message against the given key or use the default value as English
t('aftersign', {
default: 'undefined afterSign hook called from plugin template',
})
)
} else {
// eslint-disable-next-line no-console
console.log('undefined afterSign hook called with', request, context)
}
return
}
)
// Register any desired afterBroadcast hooks
context.addHook(
TransactHookTypes.afterBroadcast,
async (request, context): Promise<TransactHookResponseType> => {
// If this plugin is interacting with the UI, throw an error since this is an undefined function
if (context.ui) {
throw new Error(
// Translate the error message against the given key or use the default value as English
t('afterbroadcast', {
default: 'undefined afterBroadcast hook called from plugin template',
})
)
} else {
// eslint-disable-next-line no-console
console.log('undefined afterBroadcast hook called with', request, context)
}
return
}
)
}
}
|