Catalog npm
Back to packageRELEASE DETAILS

0.0.1-beta.7

npm

3box-profile-edit-react

A drop in component for editing 3Box profiles.

3boxdecentralizededit profileethereum
Published3 Jan 2020
Direct dependencies43
Transitive dependenciesNot calculated

README

Version 0.0.1-beta.7 documentation

Discord npm Twitter Follow

3Box Profile Edit Plugin 📝

The 3box-profile-edit-react node package is a drop-in react component that provides Web3 developers with UI and logic for editing user profiles in their Ethereum application. Quickly add customizable fields that are pertinent to your dapp on top of basic input fields, with the option of text, textarea, and select (dropdown) style inputs. The 3Box Edit Profile plugin is built using 3Box infrastructure. Read the docs on docs.3box.io.

Try the demo here

Example Screenshot

How it Works

Architecture

The Edit Profile plugin implements simple set & get methods on both the Profiles API and the Spaces API for standard fields (name, image, coverPhoto, emoji, description) depending on which profile the user chooses as their default (3Box or App), but will use only the Spaces API for custom fields added by the developer passed as a prop to the component. Both methods are made available via the 3Box.js SDK. After a user has set which default profile they'd like to use, by setting a boolean to the key isAppProfileDefault in the space's public store, the dapp should appropriately fetch from that profile elsewhere in the dapp.

Authentication

Prior to first render of the Edit Profile component, the dapp should have already run const box = await Box.openBox(userAddress, ethereumProvider) and const space = await box.openSpace(spaceName) and passed both the box and space objects as props of the same name.

Getting Started

  1. Install the component
  2. Configure application settings and props to component
  3. Usage
  4. Display correct profile in your app

1. Install the component

npm i -S 3box-profile-edit-react

2. Configure application settings and props to component

First, choose a name for your application's 3Box space.

Although you are free to choose whichever name you'd like for your app's space, we recommend using the name of your app. If your application already has a 3Box space, you are welcome to use that same one for the chatbox.

Then, configure the custom fields you'd like to add to the component

The customFields prop must receive an array of any number of objects in the following structures:

    { // for a field with a text input
        inputType: 'text',
        key: 'backupAddress', // the key used to save the value
        field: 'Backup Address' // how to display the key in the UI
      }, 

      { // for a field with a textarea input
        inputType: 'textarea',
        key: 'spiritCryptoKittie',
        field: 'Spirit CryptoKitty'
      },

      { // for a field with a dropdown input
        inputType: 'dropdown',
        key: 'preferredCoin',
        field: 'Preferred Coin',
        options: [{ // dropdown input requires an array of objects
          value: 'eth', // value passed after selection
          display: 'Ethereum' // what the user will see in the dropdown
        }, {
          value: 'btc',
          display: 'Bitcoin'
        }, {
          value: 'ltc',
          display: 'Litecoin'
        }]
      }

The Edit Profile component comes standard with Name, Emoji, and Description fields. The component defaults to using the 3Box profile (as the isAppProfileDefault boolean in the space is still undefined). Fields passed to customFields however will always be saved to the app's space.



3. Usage

The Edit Profile component can of course be used in any way the developer pleases, though we recommend it be used on a dedicated edit profile page or in a popup modal (not included) of the developer's design. Remember, both the box and space instance must be passed to the component before it mounts.

Example

import EditProfile from '3box-profile-edit-react';

const MyComponent = ({ customFields, box, space, myAddress, myProfile, redirectFn }) => (
    <EditProfile
        // required
        box={box}
        space={space}
        currentUserAddr={myAddress}

        // optional
        customFields={customFields}
        currentUser3BoxProfile={myProfile}
        redirectFn={redirectFn}
    />
);

4. Display correct profile in your app

Once a user selects a default profile (3Box or app) the decision should reflect elsewhere in your dapp. To do this, you should check isAppProfileDefault flag, then call get on the respective profile for fields name, image, coverPhoto, emoji, and description. Custom fields added to the Edit Profile component, however, are all saved to the application profile in the space used by your dapp and should get from there.

Checking and getting from the appropriate default profile should look something like this:

  const isAppProfileDefault = await space.public.get('isAppProfileDefault');

  let profile;
  if (isAppProfileDefault) {
    profile = await Box.getProfile(currentUserAddr);
  } else {
    profile = await space.public.all();
  }

  this.setState({
    name: profile.name,
    image: profile.image,
    coverPhoto: profile.coverPhoto,
    emoji: profile.emoji,
    description: profile.description,
  })

Prop Types

PropertyTypeRequiredDescription
boxObjectTrueThe box instance returned from running await Box.openBox(address, web3) somewhere in your dApp.
spaceObjectTrueThe space instance returned from running await box.openSpace(spaceName) somewhere in your dApp.
currentUserAddrString (Ethereum Address)TrueThe current user's Ethereum address. Used to fetch the user's profile if it's not provided and for other various uses in the component.
customFieldsArrayAn array of any amount of objects structured in one of three ways outlined above.
currentUser3BoxProfileObjectIf passed, it must be the object returned from calling const currentUser3BoxProfile = await Box.getProfile(myAddress);. If this is not passed, the component runs the same static method using the currentUserAddr prop
redirectFnFunctionA function that runs after saving the fields in the UI is complete, or when a user hits cancel. The user's ethereum address will be passed as a param in the event that the dapp uses this in the route

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 45

Native requirements
43 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
async
Environment
{
  "local_name": "async",
  "alias": false,
  "peer_metadata": null
}
^3.1.0runtime
emoji-js
Environment
{
  "local_name": "emoji-js",
  "alias": false,
  "peer_metadata": null
}
^3.4.1runtime
orbit-db
Environment
{
  "local_name": "orbit-db",
  "alias": false,
  "peer_metadata": null
}
^0.21.4runtime
babel-core
Environment
{
  "local_name": "babel-core",
  "alias": false,
  "peer_metadata": null
}
^7.0.0-bridge.0runtime
emoji-mart
Environment
{
  "local_name": "emoji-mart",
  "alias": false,
  "peer_metadata": null
}
^2.11.1runtime
3id-resolver
Environment
{
  "local_name": "3id-resolver",
  "alias": false,
  "peer_metadata": null
}
0.0.6runtime
@babel/runtime
Environment
{
  "local_name": "@babel/runtime",
  "alias": false,
  "peer_metadata": null
}
^7.6.0runtime
svg-inline-loader
Environment
{
  "local_name": "svg-inline-loader",
  "alias": false,
  "peer_metadata": null
}
^0.8.0runtime
ethereum-blockies-base64
Environment
{
  "local_name": "ethereum-blockies-base64",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
react-addons-css-transition-group
Environment
{
  "local_name": "react-addons-css-transition-group",
  "alias": false,
  "peer_metadata": null
}
^15.6.2runtime
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.1.2development
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^16.6.0development
enzyme
Environment
{
  "local_name": "enzyme",
  "alias": false,
  "peer_metadata": null
}
^3.3.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^5.8.0development
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^4.9.1development
jest-cli
Environment
{
  "local_name": "jest-cli",
  "alias": false,
  "peer_metadata": null
}
^23.6.0development
node-sass
Environment
{
  "local_name": "node-sass",
  "alias": false,
  "peer_metadata": null
}
^4.7.2development
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
^16.6.0development
babel-jest
Environment
{
  "local_name": "babel-jest",
  "alias": false,
  "peer_metadata": null
}
^23.6.0development
css-loader
Environment
{
  "local_name": "css-loader",
  "alias": false,
  "peer_metadata": null
}
^1.0.1development
prop-types
Environment
{
  "local_name": "prop-types",
  "alias": false,
  "peer_metadata": null
}
^15.6.0development
@babel/core
Environment
{
  "local_name": "@babel/core",
  "alias": false,
  "peer_metadata": null
}
^7.1.2development
file-loader
Environment
{
  "local_name": "file-loader",
  "alias": false,
  "peer_metadata": null
}
^4.2.0development
sass-loader
Environment
{
  "local_name": "sass-loader",
  "alias": false,
  "peer_metadata": null
}
^7.0.1development
webpack-cli
Environment
{
  "local_name": "webpack-cli",
  "alias": false,
  "peer_metadata": null
}
^3.1.2development
babel-eslint
Environment
{
  "local_name": "babel-eslint",
  "alias": false,
  "peer_metadata": null
}
^10.0.1development
babel-loader
Environment
{
  "local_name": "babel-loader",
  "alias": false,
  "peer_metadata": null
}
^8.0.4development
did-resolver
Environment
{
  "local_name": "did-resolver",
  "alias": false,
  "peer_metadata": null
}
0.0.7development
style-loader
Environment
{
  "local_name": "style-loader",
  "alias": false,
  "peer_metadata": null
}
^0.23.1development
@babel/register
Environment
{
  "local_name": "@babel/register",
  "alias": false,
  "peer_metadata": null
}
^7.0.0development
react-inlinesvg
Environment
{
  "local_name": "react-inlinesvg",
  "alias": false,
  "peer_metadata": null
}
^1.1.6development
react-hot-loader
Environment
{
  "local_name": "react-hot-loader",
  "alias": false,
  "peer_metadata": null
}
nextdevelopment
@babel/preset-env
Environment
{
  "local_name": "@babel/preset-env",
  "alias": false,
  "peer_metadata": null
}
^7.1.0development
webpack-dev-server
Environment
{
  "local_name": "webpack-dev-server",
  "alias": false,
  "peer_metadata": null
}
^3.1.4development
@babel/preset-react
Environment
{
  "local_name": "@babel/preset-react",
  "alias": false,
  "peer_metadata": null
}
^7.0.0development
eslint-plugin-react
Environment
{
  "local_name": "eslint-plugin-react",
  "alias": false,
  "peer_metadata": null
}
^7.4.0development
react-test-renderer
Environment
{
  "local_name": "react-test-renderer",
  "alias": false,
  "peer_metadata": null
}
^16.0.0development
regenerator-runtime
Environment
{
  "local_name": "regenerator-runtime",
  "alias": false,
  "peer_metadata": null
}
^0.12.1development
clean-webpack-plugin
Environment
{
  "local_name": "clean-webpack-plugin",
  "alias": false,
  "peer_metadata": null
}
^0.1.16development
enzyme-adapter-react-16
Environment
{
  "local_name": "enzyme-adapter-react-16",
  "alias": false,
  "peer_metadata": null
}
^1.1.1development
react-addons-test-utils
Environment
{
  "local_name": "react-addons-test-utils",
  "alias": false,
  "peer_metadata": null
}
^15.5.1development
@babel/plugin-proposal-class-properties
Environment
{
  "local_name": "@babel/plugin-proposal-class-properties",
  "alias": false,
  "peer_metadata": null
}
^7.5.5development
3box
Environment
{
  "local_name": "3box",
  "alias": false,
  "peer_metadata": null
}
^1.14.0peer
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
>= 16.3.0peer
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
>= 16.3.0peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "77ed125f8a39f936ea6f4fb5bfbf74575bdaf478",
  "tarball": "https://registry.npmjs.org/3box-profile-edit-react/-/3box-profile-edit-react-0.0.1-beta.7.tgz",
  "fileCount": 13,
  "integrity": "sha512-kksl98JHGemhpI0/H+57eXRH7wZCdIZ75ET6DD/jFXmrMIU2N1dLJcjz0sg5nVBwMy+CXsIIEaS8/pPAE6TbKw==",
  "signatures": [
    {
      "sig": "MEQCIHy7EZDLPiEPsSZ9xw2o4BXKBPrlklwM0l3jp5xKC+K0AiBjZcMrtcLP4kJyWbLLKnGX5aC/8YCZyfcjUA42suFxYA==",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 4602551,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeD06UCRA9TVsSAnZWagAA+VsP/1wNiccZ8jwphFaydKaI\n710uIfUEnhQiHWuJACExXGfgjOjzHg5VGUndqtaoWOxj5w5HQi87h4CmuJCc\nh72X7Nk871E0EyAtkgkX0/sJQ2qw5GhEWbmfH6UmZ+XyWe9BARQHonQufqfA\nLeRLSfd803VfSnOZe1fS6j8aXov4sXalHylZkDQ3HMy1WT8U3NWKS4HOoX0T\nkDYvCivcJyaeEHwRf9jeTHFc5wZFdw9Rc107UGbwStvyqyFpusq/dDahUXSi\ne/K6nviANjDnM4eTXQ5w7MzWHVMBHBdjSsD2EVBkEA0xV2YF5zSRi54PYja+\noXR1BJhgmompMvNx02aWr7UWlFI56WhdShhIFTXVkDhZpLXiGZt6BAZW4u9x\nJMPkwGNuWuETF7LH6WgeppOmXCRbDsZ7URBch8RJNpRP0ME5EvfrmlXpHkdw\n6EEPR1S791JP2V167nyD7jWDaxA73BST9D81iFckoplqhp0YTfaX3aFeutmj\nuQ6ab8TYXFLgVjlPjRewUyc/SfK/RPFZ6zC0vZg1A4YGKjyFnaKFDeWWG5Tx\nlASR3bCOsiAlF/sdE1XA6pENmmb+rJd+A5B/ROAlA4LcURScc+4Nk2DAy+Qt\n+aCAVXoY2D45ttax0MldZMbGWRj0COvh3pLON3qC404g2MXTsnne8GFwQJ/h\nFhT4\r\n=jA6J\r\n-----END PGP SIGNATURE-----\r\n"
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:31 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:dc5fc9d2aaf0e4020d44db09318bc282aa91e242f2b2a75fbc4bef3e2edf631b

Other collected versions

0.0.93 Apr0.0.815 Feb0.0.714 Feb0.0.66 Feb0.0.6-beta.36 Feb0.0.6-beta.26 FebView all collected versions →