Add additional plugin examples
This commit is contained in:
parent
bef7a1a74b
commit
8e3b32f79e
|
@ -24,7 +24,7 @@ const exchange = new Exchange({
|
|||
|
||||
const BurnerWallet = () =>
|
||||
<ModernUI
|
||||
title="ETHWaterloo"
|
||||
title="Basic Wallet"
|
||||
core={core}
|
||||
plugins={[exchange, new MyPlugin()]}
|
||||
/>
|
||||
|
|
|
@ -33,7 +33,7 @@ const core = new BurnerCore({
|
|||
|
||||
const BurnerWallet = () =>
|
||||
<ModernUI
|
||||
title="ETHWaterloo"
|
||||
title="Local Wallet"
|
||||
core={core}
|
||||
plugins={[new MyPlugin()]}
|
||||
/>
|
||||
|
|
|
@ -2,12 +2,34 @@ import { BurnerPluginContext, Plugin } from '@burner-wallet/types';
|
|||
import MyPage from './ui/MyPage';
|
||||
import MyElement from './ui/MyElement';
|
||||
|
||||
interface PluginActionContext {
|
||||
actions: Actions;
|
||||
}
|
||||
|
||||
export default class MyPlugin implements Plugin {
|
||||
private pluginContext: BurnerPluginContext;
|
||||
|
||||
initializePlugin(pluginContext: BurnerPluginContext) {
|
||||
this.pluginContext = pluginContext;
|
||||
|
||||
pluginContext.addPage('/my-page', MyPage);
|
||||
pluginContext.addButton('apps', 'My Plugin', '/my-page', {
|
||||
description: 'Sample plugin page',
|
||||
});
|
||||
pluginContext.addElement('home-middle', MyElement);
|
||||
|
||||
onQRScanned: ((scan: string, ctx: PluginActionContext) => {
|
||||
if (scan === 'My Plugin') {
|
||||
ctx.actions.navigateTo('/my-page');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getBlockNum() {
|
||||
const assets = this.pluginContext!.getAssets();
|
||||
const web3 = this.pluginContext!.getWeb3(assets[0].network);
|
||||
const blockNum = web3.eth.getBlockNumber();
|
||||
return blockNum;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { BurnerContext } from '@burner-wallet/types';
|
||||
import MyPlugin from '../MyPlugin';
|
||||
|
||||
const MyElement: React.FC<BurnerContext> = ({ plugin }) => {
|
||||
const [block, setBlock] = useState<string | null>(null);
|
||||
const _plugin = plugin as MyPlugin;
|
||||
|
||||
useEffect(() => {
|
||||
_plugin.getBlockNum().then((num: string) => setBlock(num))
|
||||
}, []);
|
||||
|
||||
const MyElement: React.FC<BurnerContext> = () => {
|
||||
return (
|
||||
<div>
|
||||
Injected plugin element
|
||||
<div>Injected plugin element</div>
|
||||
{block && (
|
||||
<div>Current block number: {block}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue