Commit Graph

507 Commits

Author SHA1 Message Date
Evgeny Kuzyakov
a6ed652ff5
Merge pull request #123 from NearSocial/missing-changes
## 2.4.2

- Add missing code changes (`cacheOptions` and `lodash`) from 2.4.0.
> This happened due to revert from master that later cleaned changes from dev at merge conflict.
2023-09-20 09:36:38 -07:00
Evgeny Kuzyakov
120e0d6f9a Amend changelog 2023-09-20 09:33:28 -07:00
Evgeny Kuzyakov
15d6d8522b Bump version to 2.4.2 2023-09-20 09:32:03 -07:00
Evgeny Kuzyakov
c92248dd82 Replace lodash dep with lodash.clonedeep 2023-09-20 09:30:34 -07:00
Evgeny Kuzyakov
fe3078c20f Introduce cacheOptions 2023-09-20 09:24:54 -07:00
Evgeny Kuzyakov
8cdb3193c6
Merge pull request #117 from NearSocial/fix-2.4.1
## 2.4.1

- FIX: Resolve bug with `VM.require` affected by the introduction of `useState` and `useEffect` hooks.
2023-09-14 08:58:42 -07:00
Evgeny Kuzyakov
6fbc54ade6 2.4.1: Fix VM.require 2023-09-14 08:55:28 -07:00
Evgeny Kuzyakov
9f8acccced
Merge pull request #116 from NearSocial/release-2.4.0
## 2.4.0

- Introduce `useState` and `useEffect`. They should work similarly to the React hooks. Example:
```jsx
const [a, setA] = useState(() => {
  console.log("Init 'a'");
  return "Y";
});

const [b, setB] = useState("B");
const [sum, setSum] = useState(0);

useEffect(() => {
  setSum(a.length + b.length);
  return () => {
    console.log("cleanup");
  };
}, [a, b]);

return (
  <div>
    A = {a}
    <br />B = {b}
    <br />
    Length sum = {sum}
    <div>
      <button onClick={() => setA((s) => s + "O")}>A</button>
      <button onClick={() => setB(b + "O")}>B</button>
    </div>
  </div>
);
```

- Add `cacheOptions` optional argument to the following methods:
  - `Social.get(keys, blockId|finality, options, cacheOptions)`
  - `Social.getr(keys, blockId|finality, options, cacheOptions)`
  - `Social.keys(keys, blockId|finality, options, cacheOptions)`
  - `Social.index(action, key, options, cacheOptions)`
  - `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
  - `Near.block(blockId|finality, subscribe, cacheOptions)`
    The `cacheOptions` object is optional and may contain the following property:
  - `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.

This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
  "post",
  "main",
  {
    limit: 10,
    order: "desc",
  },
  {
    ignoreCache: true,
  }
);
```
- Replace `lodash` dependency with `lodash.clonedeep` to reduce bundle size.
2023-09-13 12:46:05 -07:00
Evgeny Kuzyakov
e16b5e0713 Release 2.4.0 2023-09-13 12:39:37 -07:00
Evgeny Kuzyakov
f42b260544 Merge branch 'dev' of github.com:NearSocial/VM into dev 2023-09-13 12:36:47 -07:00
Evgeny Kuzyakov
6a9f78c660
Merge pull request #115 from NearSocial/react-use-state
- Introduce `useState` and `useEffect`. They should work similarly to the React hooks. Example:
```jsx
const [a, setA] = useState("Y");

const [b, setB] = useState("B");
const [sum, setSum] = useState(0);

useEffect(() => {
  setSum(a.length + b.length);
  return () => {
    console.log("cleanup");
  };
}, [a, b]);

return (
  <div>
    A = {a}
    <br />B = {b}
    <br />
    Length sum = {sum}
    <div>
      <button onClick={() => setA(a + "O")}>A</button>
      <button onClick={() => setB(b + "O")}>B</button>
    </div>
  </div>
);
```
2023-09-13 10:16:14 -07:00
Evgeny Kuzyakov
cab61a0e73 Simplify code 2023-09-13 10:12:01 -07:00
Evgeny Kuzyakov
37b9fb7dff Expand example with functions 2023-09-13 10:09:22 -07:00
Evgeny Kuzyakov
bc3281c233 Update to use isFunction 2023-09-13 10:00:34 -07:00
Evgeny Kuzyakov
90b415f5c3 Replace isFunction import 2023-09-13 09:44:54 -07:00
Evgeny Kuzyakov
837c9f7af8 Introduce useState and useEffect 2023-09-12 15:01:19 -07:00
Evgeny Kuzyakov
27ec908e57
Merge pull request #114 from NearSocial/no-stale
- Add `cacheOptions` optional argument to the following methods:
  - `Social.get(keys, blockId|finality, options, cacheOptions)`
  - `Social.getr(keys, blockId|finality, options, cacheOptions)`
  - `Social.keys(keys, blockId|finality, options, cacheOptions)`
  - `Social.index(action, key, options, cacheOptions)`
  - `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
  - `Near.block(blockId|finality, subscribe, cacheOptions)`
The `cacheOptions` object is optional and may contain the following property:
  - `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.

This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
  "post",
  "main",
  {
    limit: 10,
    order: "desc",
  },
  {
    ignoreCache: true,
  }
);
```
2023-09-11 10:14:36 -07:00
Evgeny Kuzyakov
446e4a08ae
Merge pull request #113 from NearSocial/revert-106-no-stale
Reverts NearSocial/VM#106 

Should be merged to `dev` instead
2023-09-11 10:03:37 -07:00
Evgeny Kuzyakov
23a9b08f1a
Revert "Introduce cacheOptions" 2023-09-11 10:03:05 -07:00
Evgeny Kuzyakov
dd0afdeae2
Merge pull request #106 from NearSocial/no-stale
- Add `cacheOptions` optional argument to the following methods:
  - `Social.get(keys, blockId|finality, options, cacheOptions)`
  - `Social.getr(keys, blockId|finality, options, cacheOptions)`
  - `Social.keys(keys, blockId|finality, options, cacheOptions)`
  - `Social.index(action, key, options, cacheOptions)`
  - `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
  - `Near.block(blockId|finality, subscribe, cacheOptions)`
The `cacheOptions` object is optional and may contain the following property:
  - `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.

This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
  "post",
  "main",
  {
    limit: 10,
    order: "desc",
  },
  {
    ignoreCache: true,
  }
);
```
2023-09-11 10:02:51 -07:00
Evgeny Kuzyakov
c34378da37 Merge branch 'dev' of github.com:NearSocial/VM into no-stale 2023-09-08 09:17:08 -07:00
Evgeny Kuzyakov
4c24d257b4
Merge pull request #107 from NearSocial/remove-lodash-dep
Replace lodash dep with lodash.clonedeep
2023-09-08 09:00:41 -07:00
Evgeny Kuzyakov
ca3833241d rebuild 2023-08-27 19:17:55 -07:00
Evgeny Kuzyakov
45cd2e023e Replace lodash dep with lodash.clonedeep 2023-08-27 18:58:52 -07:00
Evgeny Kuzyakov
987c59a6b5 Introduce cacheOptions 2023-08-27 18:10:53 -07:00
Evgeny Kuzyakov
901945ddde Version 2.3.2 2023-08-27 18:08:10 -07:00
Evgeny Kuzyakov
24fdbf1b60 Bump version in package.json (was missing in the previous release) 2023-08-27 16:33:02 -07:00
Evgeny Kuzyakov
7c5bfced7f
Merge pull request #104 from NearSocial/fix/ethers-send-2.3.1
2.3.1: Fix Ethers.send
2023-08-22 18:24:52 -07:00
Evgeny Kuzyakov
52fdb213fa Add examples to CHANGELOG 2023-08-22 18:24:12 -07:00
Evgeny Kuzyakov
dfa8bd74e8 Revert change for Ethers.send 2023-08-21 20:48:53 -07:00
Evgeny Kuzyakov
609937473b 2.3.1: Fix Ethers.send 2023-08-21 09:51:32 -07:00
Evgeny Kuzyakov
240abd0cb4
Merge pull request #103 from NearSocial/release-2.3.0
## 2.3.0

- Expose `encodeURIComponent`, `decodeURIComponent`, `btoa`, `atob`, `isFinite`, `decodeURI` and `encodeURI` in the global scope.
- Refactor native functions into an object, making it easier to add new functions.
- Add a `networkId` prop to the `Widget` component config to allow using a `near` object outside the singleton state to allow testing Mainnet components on a Testnet initialized VM or vice versa. Example usage of `networkId` prop in `Widget` config:

```jsx
// Import widget from testnet initialized VM

<Widget 
  config={{
    networkId: 'mainnet'
  }}
  src="devgovgigs.near/widget/Ideas" // `src` prop here is a path in mainnet SocialDB
/>

// Also works with the `code` prop where `Social.get` and other [BOS API](https://docs.near.org/bos/api/near#) features and `Widget`s will reference mainnet in this case.
```
- Expose `Ethers.setChain({chainId})` to be able to switch between EVM networks. Note, the gateway should inject it as part of the `EthersProviderContext`.
- Add `config.defaultFinality` to be able to specify `final` instead of `optimistic` (default). It would route the majority of the view calls through the API server.
- Expose `ethers.providers`. You will be able to construct a custom JSON provider for read only data. Example usage:

```jsx
const opGoerliProvider = new ethers.providers.JsonRpcProvider(
  "https://optimism-goerli.blockpi.network/v1/rpc/public"
);

console.log(opGoerliProvider);
```
- BREAKING: Update `Ethers.send` to ignore cache and return a promise instead of the cached value.
- Add `loading` prop to a Widget. It would display the passed value instead of the default loading spinner. It can be used to display a custom loading indicator or a placeholder. Example:
```jsx
<Widget
  loading={<div style={{width: "100%", height: "200px"}}>Loading...</div>}
  src="mob.near/widget/ProfilePage"
/>
```
2023-08-18 11:47:34 -07:00
Evgeny Kuzyakov
5cfaf0a7b4 2.3.0: Release 2023-08-18 11:45:19 -07:00
Evgeny Kuzyakov
063a1cf3ce
Merge pull request #100 from NearSocial/loading-placeholder
Add `loading` prop to a Widget. It would display the passed value instead of the default loading spinner. It can be used to display a custom loading indicator or a placeholder. Example:
```jsx
<Widget
  loading={<div style={{width: "100%", height: "200px"}}>Loading...</div>}
  src="mob.near/widget/ProfilePage"
/>
2023-08-18 11:22:02 -07:00
Evgeny Kuzyakov
136913127b Merge branch 'dev' of github.com:NearSocial/VM into loading-placeholder 2023-08-17 10:04:53 -07:00
Evgeny Kuzyakov
3ee33ed2ca
Merge pull request #85 from NearSocial/fix-ethers-call
- BREAKING: Update `Ethers.send` to ignore cache and return a promise instead of the cached value.
2023-08-17 09:50:31 -07:00
Evgeny Kuzyakov
cc0f5372cd Merge branch 'dev' of github.com:NearSocial/VM into fix-ethers-call 2023-08-17 09:49:00 -07:00
Evgeny Kuzyakov
6ef7d5b141
Merge pull request #101 from NearSocial/expose-ethers-providers
- Expose `ethers.providers`. You will be able to construct a custom JSON provider for read only data. Example usage:

```jsx
const opGoerliProvider = new ethers.providers.JsonRpcProvider(
  "https://optimism-goerli.blockpi.network/v1/rpc/public"
);

console.log(opGoerliProvider);
```
2023-08-17 09:44:05 -07:00
Evgeny Kuzyakov
643ecd0b6a Expose ethers.providers 2023-08-14 09:44:11 -07:00
Evgeny Kuzyakov
1dc27f1310 Add loading prop to Widget 2023-08-11 21:10:36 -07:00
Evgeny Kuzyakov
6e29c48f8c
Merge pull request #99 from NearSocial/default-finality
- Add `config.defaultFinality` to be able to specify `final` instead of `optimistic` (default). It would route the majority of the view calls through the API server.
2023-08-10 11:40:58 -07:00
Evgeny Kuzyakov
3f30c043f8 Add config.defaultFinality 2023-08-09 13:13:52 -07:00
Evgeny Kuzyakov
186bdea1d7 Merge branch 'master' of github.com:NearSocial/VM into dev 2023-07-28 10:10:32 -07:00
Evgeny Kuzyakov
e0b9920661
Merge pull request #89 from near-everything/fix/vm-require-breaks-state
this.vmInstances is a map and so must be accessed with .get rather than bracket notation.
Resolves #88
2023-07-14 14:24:57 -07:00
Elliot Braem
261753f4dd bumps patch version to 2.2.4 2023-07-13 13:21:01 -04:00
Elliot Braem
203623f5b7 fix: accesses vm instance map with a .get 2023-07-12 14:38:26 -04:00
Evgeny Kuzyakov
9f4f7685e3 Remove caching from Ethers.send 2023-07-06 09:53:43 -07:00
Evgeny Kuzyakov
d1ff86f29b
Merge pull request #80 from NearSocial/network-switcher
- Expose `Ethers.setChain({chainId})` to be able to switch between EVM networks.

Note:`setChain` callback should be provided by the gateway through `EthersProviderContext`. If it's not provided the call from the VM will fail with an exception. See https://github.com/NearSocial/viewer/pull/174 as an example on how to expose `setChain`
2023-07-06 09:41:36 -07:00
Evgeny Kuzyakov
a84287938e Merge branch 'dev' of github.com:NearSocial/VM into network-switcher 2023-07-06 09:40:01 -07:00
Evgeny Kuzyakov
55ce6845b6
Merge pull request #82 from esaminu/main
This PR adds a fix to return an `accountId` in `useAccountId` if a `null` `networkId` is passed to is as an argument
2023-06-29 09:31:35 -07:00