Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
fix example ports; update 3box
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Oct 1, 2019
1 parent e7eeda2 commit dc94b7e
Show file tree
Hide file tree
Showing 16 changed files with 7,595 additions and 185 deletions.
3 changes: 1 addition & 2 deletions examples/3box/.mm-plugin.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": ".",
"port": 8083
}
}
4 changes: 4 additions & 0 deletions examples/3box/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# 3box Plugin

**NOTE:** This plugin is currently not supported and will be updated in the future.
240 changes: 190 additions & 50 deletions examples/3box/dist/bundle.js

Large diffs are not rendered by default.

52 changes: 49 additions & 3 deletions examples/3box/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
const Box = require('3box/dist/3box.min')

// const plug = require('./src/3box-example')
// const plug = require('./src/example1')
const plug = require('./src/3box-example-basic')
function update3Box ({ type, box }, newState) {
console.log('3boxbasic update3Box type:', type);
console.log('3boxbasic update3Box newState:', newState);
return box.private.set(type, JSON.stringify(newState));
}

function registerUpdates (box) {
const updatePreferences = update3Box.bind(this, { type: 'preferences', box });
console.log('3boxbasic registerUpdates:', `updatePreferences:${updatePreferences} box:${box}`);
pluginAPIs.subscribeToPreferencesControllerChanges(updatePreferences);
}

function restoreFrom3Box (box, address) {
box.private.get('preferences')
.then(backedUpPreferences => {
console.log('backedUpPreferences', backedUpPreferences)
backedUpPreferences && pluginAPIs.updatePreferencesControllerState(JSON.parse(backedUpPreferences));
registerUpdates(box);
console.log('3boxbasic restoreFrom3Box:', `address:${address} box:${box} backedUpPreferences:${backedUpPreferences}`);
pluginAPIs.updatePluginState({ syncDone3Box: true, threeBoxAddress: address });
})
}

function new3Box (address) {
pluginAPIs.updatePluginState({ syncDone3Box: false });
console.log('3boxbasic new3Box 1:', `address:${address}`);
pluginAPIs.generateSignature('This app wants to view and update your 3Box profile.', address)
.then(signature => pluginAPIs.Box.openBox(
address,
ethereumProvider,
{
walletProvidedSignature: signature
}
))
.then(box => {
box.onSyncDone(() => {
restoreFrom3Box(box, address);
console.log('3boxbasic new3Box 2:', `address:${address} box:${box}`);
pluginAPIs.updatePluginState({ syncDone3Box: true, threeBoxAddress: address });
})
})
}

function metaPlugin () {
new3Box(pluginData.address)
}

metaPlugin()
Loading

0 comments on commit dc94b7e

Please sign in to comment.