react-steem-provider
What is react-steem-provider?
Start quickly a steem project with this flexible library that combines SteemConnect and Steem
Content
2. Using SteemConnect Context.
- Step 1: Setting up our provider.
- Step 2: Using the context consumer.
- What is in the steem instance?
1.Installing
$ npm install react-steem-provider$ yarn add react-steem-provider
2.Using SteemConnect Context.
This library implements a context provider to manage the login state and other steemConnect instances.
Step 1: Setting up the context provider (you MUST do this step)
When the context provider is mounted, checks if there is the callback url with the token from SteemConnect to authenticate the user automatically.
Note: The context provider requires the Steem Connect configJSON of your project
App.js
;;; //Caution! //SteemConnect Config JSONconst STEEM_CONFIG = baseURL: 'https://steemconnect.com' app: '<appname>' callbackURL: "<callbackURL>" scope: 'login' 'vote' 'comment' 'delete_comment' 'comment_options' 'custom_json' ; const App = { return <SteemProvider config=STEEM_CONFIG> <Dashboard /> </SteemProvider> ;} ;
Step 2: Using the Steem Context Consumer.
Once we have the SteemProvider in a parent component (App.js) we need to consume our Context Provider to use the instances and functions from SteemConnect, in React there are many options to consume context, let's some of them.
(Option A) - Using steem context consumer with useContext (hooks)
Note: Your React version must be >= 16.8 to use hooks
Dahsboard.js
;; const Dashboard = { const loginUrl auth loading } = ; ifloading return <h1>Loading please wait...</h1> return <ReactFragment> auth?<h1>You are logged</h1>:<a href=loginUrl>Log in</a> </ReactFragment> } ;
(Option B) - Using steem context consumer with withSteem (HOC)
Dahsboard.js
;; //CONSUMER HOC //Note: withSteem(HOC) is responsible of the **steem** prop. const Dashboard = ; ; /*NOTE: Instead of using withSteem (HOC), you can import the **SteemContext** as well to use it's Consumer .import {SteemContext} from 'react-steem-provider'; <SteemContext.Consumer>{(steem)=>{ return <h1><SteemContext.Consumer></h1>}}</SteemContext.Consumer> */
What is in the steem instance?
List of instances from SteemContext (steem)
loginUrl//SteemConnect loginUrl auth //steem user or null steemConnect//steemConnect original instance (client) logout //logout function loading //true when auth is loading actions //Set of writtig functions
List of actions from SteemContext (steem.actions)
Note: You MUST be logged to use some actions
- Get logged user
await steemactions
- Publish a post
await steemactions
post_params
post_params = permlink /*This is not required an uuidv4 id is replace in case if npt pasing this argument*/ title body category parent_permlink jsonmetadata = {}
advanced (optional)
advanced = exetions:{}...
- Reply post
await steemactions
reply_params
reply_params = author post body jsonmetadata = {}
advanced (optional)
advanced = exetions:{}...
- Remove post
await steemactions
- Create regular post
await steemactions
- Reblog Post
await steemactions
- Follow account
await steemactions
- Unfollow account
await steemactions
- Claim Reward Balance
await steemactions
- Update User Metadata
await steemactions
- Remove token
await steemactions
3.Async Steem functions:
A simplificated set of async steem functions.
Note: you dont need to use the SteemContext to implement this functions
;
- List of posts in the platform.
// getBy: "Trending | Created | Hot | Promoted" SteemAsync;
- Get full post
SteemAsync;
- Get user by username
const user = await SteemAsync;
- List of posts in an account
const post = await SteemAsync;
- Get Follows Count in an account
SteemAsync;
- Get following
await SteemAsync;
- Get Followers
const followers = SteemAsync;
You can access to the steem.js package:
;
4.Helpers
Useful functions for your steem project.
- Parse reputation
;
- Parse Steem markdown
;
5.Example
Dahsboard.js
Note: Remember to implement the context provider as parent component.
;;; const PrintPost = { const actions auth = ; ; const makeANewPost = { actions ; }; if !auth throw "User not logged"; return <ReactFragment> <h1> This button create a post in your blog be wise when you click on it" " </h1> <button onClick=makeANewPost>Make a </button> </ReactFragment> ;}; const Dashboard = { const auth loginUrl = ; return <ReactFragment> auth ? <PrintPost /> : <a href=loginUrl>Log in</a> </ReactFragment> ;}; ;
Contribute
Help us to make of this an epic package.
License
Licensed under MIT