shogun-button-react 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ import { ShogunCore } from "shogun-core";
2
+ export function shogunConnector(options) {
3
+ const { peers = ["https://gun-manhattan.herokuapp.com/gun"], appName, logging, timeouts, oauth, ...restOptions } = options;
4
+ const sdk = new ShogunCore({
5
+ peers,
6
+ scope: appName,
7
+ logging,
8
+ timeouts,
9
+ oauth,
10
+ });
11
+ const setProvider = (provider) => {
12
+ if (!sdk) {
13
+ return false;
14
+ }
15
+ try {
16
+ let newProviderUrl = null;
17
+ if (provider && provider.connection && provider.connection.url) {
18
+ newProviderUrl = provider.connection.url;
19
+ }
20
+ else if (typeof provider === "string") {
21
+ newProviderUrl = provider;
22
+ }
23
+ if (newProviderUrl) {
24
+ if (typeof sdk.setRpcUrl === "function") {
25
+ return sdk.setRpcUrl(newProviderUrl);
26
+ }
27
+ }
28
+ return false;
29
+ }
30
+ catch (error) {
31
+ console.error("Error setting provider:", error);
32
+ return false;
33
+ }
34
+ };
35
+ const getCurrentProviderUrl = () => {
36
+ if (sdk && typeof sdk.getRpcUrl === "function") {
37
+ return sdk.getRpcUrl();
38
+ }
39
+ return null;
40
+ };
41
+ const registerPlugin = (plugin) => {
42
+ if (sdk && typeof sdk.register === "function") {
43
+ try {
44
+ sdk.register(plugin);
45
+ return true;
46
+ }
47
+ catch (error) {
48
+ console.error(`Error registering plugin: ${plugin.name}`, error);
49
+ return false;
50
+ }
51
+ }
52
+ return false;
53
+ };
54
+ const hasPlugin = (name) => {
55
+ return sdk ? sdk.hasPlugin(name) : false;
56
+ };
57
+ return {
58
+ sdk,
59
+ options,
60
+ setProvider,
61
+ getCurrentProviderUrl,
62
+ registerPlugin,
63
+ hasPlugin,
64
+ };
65
+ }