You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Preparing a new Widget](#preparing-a-new-widget)
46
+
-[Testing the Application Inside the Widget](#testing-the-application-inside-the-widget)
47
+
48
+
## Complete Guide
49
+
50
+
Here's a complete guide where you can go over all features provided by Near Social Bridge.
51
+
52
+
-[Setup](#setup)
53
+
-[BOS API](#bos-api)
54
+
-[Near API](#near-api)
55
+
-[Social API](#social-api)
56
+
-[Storage API](#storage-api)
31
57
-[Requests](#requests)
32
58
-[Simple Request](#simple-request)
33
59
-[Create Requests Mocks](#create-requests-mocks)
@@ -95,6 +121,137 @@ const App = () => {
95
121
}
96
122
```
97
123
124
+
## BOS API
125
+
126
+
We've incorporated some APIs to allow your app to interact with different blockchains, websites, and store data in a decentralized way. These features are basically mirroring the [BOS API](https://docs.near.org/bos/api/home) features.
127
+
128
+
There is a deployed `Hello World` smart contract in the NEAR network at `nearsocialexamples.near` that we're going to use. The contract exposes two methods:
129
+
130
+
-`set_greeting(message: string): void`, which accepts a message and stores it in the contract state.
131
+
-`get_greeting(): string` which returns the stored greeting.
132
+
133
+
### Near API
134
+
135
+
A convenient API to interact with the NEAR blockchain. [Complete Docs Here](https://docs.near.org/bos/api/near).
136
+
137
+
**Near.view**
138
+
139
+
This will conduct a call to a smart contract that will get a stored message onchain.
`Storage.get(key, widgetSrc?)` - returns the public value for a given key under the given widgetSrc or the current component if `widgetSrc` is omitted. Can only read public values.
`Storage.privateSet(key, value)` - sets the private value for a given key under the current component. The value is private, only the current component can read it.
You can make requests to the Widget and each request must be handled appropriately by the Widget. You can also mock your requests so that they work locally while you are developing the application. All mocks will be automatically disabled when the app is running inside the Widget.
This feature stores data for one session. While testing inside a Widget, data is lost when the browser tab is reloaded or closed. You will have access to methods like `setItem`, `getItem`, `removeItem`, `clear` and `keys`. Data is automatically synchronized between the React App and the Widget.
502
+
This feature stores data for components that is persistent across refreshes. You will have access to methods like `setItem`, `getItem`, `removeItem`, `clear` and `keys`. Data is automatically synchronized between the React App and the BOS Component.
console.log(initialPayload) // initial payload sent by the Widget
576
+
console.log(initialPayload) // initial payload sent by the BOS Component
420
577
// ...
421
578
}
422
579
```
@@ -469,15 +626,15 @@ const MyComponent = () => {
469
626
470
627
### useWidgetView
471
628
472
-
Provides access to methods and props which can affect the Widget View:
629
+
Provides access to methods and props which can affect the BOS Component View:
473
630
474
631
```ts
475
632
import { useWidgetView } from'near-social-bridge'
476
633
477
634
const MyComponent = () => {
478
635
const widgetView =useWidgetView()
479
636
480
-
// Set the widget view height to 700px
637
+
// Set the BOS Component view height to 700px
481
638
widgetView.setHeight(700)
482
639
}
483
640
```
@@ -552,7 +709,7 @@ useEffect(() => {
552
709
553
710
### overrideLocalStorage
554
711
555
-
This is a feature that overrides the `window.localStorage` with the Widget's `Storage`, so that, you can keep using `window.localStorage` but the Widget's `Storage` is going to be the source of data.
712
+
This is a feature that overrides the `window.localStorage` with the BOS Component's `Storage`, so that, you can keep using `window.localStorage` but the BOS Component's `Storage` is going to be the source of data.
556
713
557
714
**If using CSR:**
558
715
@@ -562,7 +719,7 @@ import { overrideLocalStorage } from 'near-social-bridge/utils'
562
719
// using `sessionStorage` under the hood
563
720
overrideLocalStorage()
564
721
565
-
// The Widget won't break
722
+
// The BOS Component won't break
566
723
localStorage.setItem('name', 'Wenderson')
567
724
localStorage.getItem('name') // "Wenderson"
568
725
```
@@ -605,9 +762,9 @@ const MyComponent2 = () => {
605
762
}
606
763
```
607
764
608
-
## Preparing a new Widget
765
+
## Preparing a new BOS Component
609
766
610
-
Create a new Widget, copy [the content of file **widget-setup.js**](./widget-setup.js) and paste it inside your new Widget. Then set its initial props as you wish:
767
+
Create a new BOS Component, copy [the content of file **widget-setup.js**](./widget-setup.js) and paste it inside your new BOS Component. Then set its initial props as you wish:
// NearSocialBridgeCore widget is the core that makes all the "magic" happens
807
+
// NearSocialBridgeCore BOS Component is the core that makes all the "magic" happens
651
808
// use `wendersonpires.testnet/widget/NearSocialBridgeCore` as source if you want to use "testnet" environment
652
809
return (
653
810
<Widget
@@ -665,17 +822,17 @@ return (
665
822
666
823
**testnet:** Use `wendersonpires.testnet/widget/NearSocialBridgeCore` while creating your application using the testnet environment.
667
824
668
-
And that's basically it. Again, remember that once your application is running inside the Widget, if it is making requests, you must handle each one of them inside the Widget, otherwise the unhandled requests will fail.
825
+
And that's basically it. Again, remember that once your application is running inside the BOS Component, if it is making requests, you must handle each one of them inside the BOS Component, otherwise the unhandled requests will fail.
669
826
670
827
## Good to know
671
828
672
829
### Server-Side Rendering
673
830
674
831
SSR is supported starting with version 1.3.0!
675
832
676
-
## Testing the Application Inside the Widget
833
+
## Testing the Application Inside a Local Viewer
677
834
678
-
To test your app, you can install the [**NEAR Social Local Viewer CLI**](https://github.com/wpdas/near-social-local-viewer). It will allow you to execute and test your Widget locally using all the Discovery API resources without any problem.
835
+
To test your app, you can install the [**NEAR Social Local Viewer CLI**](https://github.com/wpdas/near-social-local-viewer). It will allow you to execute and test your BOS Component locally using all the Discovery API resources without any problem.
679
836
680
837
1 - Install NEAR Social Local Viewer CLI using npm or yarn:
Copy file name to clipboardExpand all lines: package.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
{
2
2
"name": "near-social-bridge",
3
-
"version": "1.4.1",
3
+
"version": "1.5.0",
4
4
"description": "This library allows you to create a common application using ReactJS and inject it in a controlled way into a Widget on Near Social. Therefore, the Widget talks to the React application and vice versa, making it possible to consume Discovery API resources within the React application.",
0 commit comments