Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rel. 1] Mutable Web. B.O.S-VM patch #180

Open
wants to merge 43 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9b1bfee
Introduce widget source overrides
alsakhaev Aug 30, 2023
7fcecf8
Auto confirm transactions
alsakhaev Aug 31, 2023
695d1c9
feat: add data-bos-src attributes for each level of bos components
alsakhaev Sep 1, 2023
4ccc1ea
fix: bos components are not rerendered when overrides changed
alsakhaev Sep 1, 2023
6ba2321
Merge remote-tracking branch 'upstream/master'
alsakhaev Oct 10, 2023
a61c937
chore: update react-singleton-hook
alsakhaev Oct 10, 2023
7310d36
Merge remote-tracking branch 'upstream/master'
alsakhaev Nov 1, 2023
4f11db7
Revert "feat: add data-bos-src attributes for each level of bos compo…
alsakhaev Nov 1, 2023
ef8ddbe
Revert "Auto confirm transactions"
alsakhaev Nov 1, 2023
318f74c
feat: allow to disable pop-ups that require the user to confirm each …
alsakhaev Nov 2, 2023
aa3b9d8
BREAKING CHANGE: add `data-component` attribute to root nodes only
alsakhaev Nov 2, 2023
7709285
chore: rebuild index.js
alsakhaev Nov 2, 2023
e36684c
feat: override props
alsakhaev Nov 8, 2023
8940215
feat: prevent recursive overriding
alsakhaev Nov 8, 2023
1b6dfb7
feat: insert structured data to DOM node
alsakhaev Dec 15, 2023
0cfd9a9
Merge remote-tracking branch 'upstream/release-2.5.3' into override-p…
alsakhaev Dec 27, 2023
5b1b682
chore: rebuild index.js
alsakhaev Dec 27, 2023
7388836
Merge branch 'override-props' into structured-data
alsakhaev Dec 27, 2023
2ba7b77
chore: rebuild index.js
alsakhaev Dec 27, 2023
ca8460b
feat: allow slot html tag
alsakhaev Dec 29, 2023
a53154f
refactor: use `styled-components` as a peer dependency
alsakhaev Jan 22, 2024
10300d3
chore: rebuild
alsakhaev Jan 22, 2024
219b4de
Merge remote-tracking branch 'upstream/master' into shadow-dom-slot
alsakhaev Jan 23, 2024
d477e6e
chore: rebuild
alsakhaev Jan 23, 2024
be00a35
Merge remote-tracking branch 'upstream/master' into shadow-dom-slot
alsakhaev Feb 15, 2024
6e3c4b8
Revert "Introduce widget source overrides"
alsakhaev Feb 22, 2024
b23926b
chore: rebuild
alsakhaev Feb 22, 2024
fd21b8b
Revert "feat: allow slot html tag"
alsakhaev Feb 22, 2024
cb3966b
chore: rebuild
alsakhaev Feb 22, 2024
997ba42
Merge remote-tracking branch 'upstream/master'
alsakhaev Apr 9, 2024
f0b4afb
chore: rebuild
alsakhaev Apr 9, 2024
5784ab7
Merge remote-tracking branch 'upstream/master'
alsakhaev Apr 24, 2024
80e61b3
Revert "feat: allow to disable pop-ups that require the user to confi…
alsakhaev Apr 24, 2024
ffd6435
chore: rebuild
alsakhaev Apr 24, 2024
3405ffe
feat: allow gateway to override built-in components
alsakhaev Apr 24, 2024
7be2628
chore: rebuild
alsakhaev Apr 24, 2024
42dac63
Reapply "feat: allow to disable pop-ups that require the user to conf…
alsakhaev May 8, 2024
70887be
chore: rebuild
alsakhaev May 8, 2024
e26d18a
chore: upgrade react-markdown to resolve defaultProps warning
alsakhaev Aug 14, 2024
37ae1fb
chore: rebuild
alsakhaev Aug 14, 2024
de8a21d
chore: upgrade react-files to resolve defaultProps warning
alsakhaev Aug 14, 2024
276a653
fix: error null.split() in mutable web extension
alsakhaev Aug 14, 2024
574951a
chore: rebuild
alsakhaev Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@
"react-bootstrap": "^2.5.0",
"react-bootstrap-typeahead": "^6.0.0",
"react-error-boundary": "^3.1.4",
"react-files": "^3.0.0-alpha.3",
"react-files": "^3.0.1",
"react-infinite-scroller": "^1.2.6",
"react-markdown": "^7.1.0",
"react-singleton-hook": "^3.1.1",
"react-markdown": "^9.0.1",
"react-singleton-hook": "^4.0.1",
"react-syntax-highlighter": "^15.5.0",
"react-uuid": "^1.0.2",
"remark-gfm": "^3.0.1",
"styled-components": "^5.3.6",
"tweetnacl": "^1.0.3"
},
"devDependencies": {
Expand Down Expand Up @@ -101,7 +100,8 @@
"peerDependencies": {
"near-api-js": "2.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"styled-components": "^5.3.6"
},
"scripts": {
"webpack": "webpack",
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const Markdown = (props) => {
} = props;
return (
<ReactMarkdown
plugins={[]}
rehypePlugins={[]}
remarkPlugins={[gfm, mentions, hashtags]}
children={text}
Expand Down
11 changes: 9 additions & 2 deletions src/lib/components/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ export const Widget = React.forwardRef((props, forwardedRef) => {
deposit: t.deposit ? Big(t.deposit) : Big(0),
gas: t.gas ? Big(t.gas) : TGas.mul(30),
}));
console.log("confirm txs", transactions);
setTransactions(transactions);

if (near.features.skipTxConfirmationPopup) {
near.sendTransactions(transactions);
} else {
console.log("confirm txs", transactions);
setTransactions(transactions);
}
},
[near]
);
Expand All @@ -157,6 +162,7 @@ export const Widget = React.forwardRef((props, forwardedRef) => {
return;
}
setReactState({ hooks: [], state: undefined });

const vm = new VM({
near,
rawCode: code,
Expand Down Expand Up @@ -204,6 +210,7 @@ export const Widget = React.forwardRef((props, forwardedRef) => {
if (!vm) {
return;
}

const vmInput = {
props: propsProps || {},
context,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/data/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ async function updateAccount(near, walletState) {
near.accountId = walletState?.accounts?.[0]?.accountId ?? null;
if (near.accountId) {
near.publicKey = null;

// Mutable Web Extension doesn't store keys in the local storage
// ToDo: parametrize key storage and pass internal extension storage to the VM
if (walletState?.selectedWalletId === "mutable-web-extension") {
return;
}

try {
if (walletState?.selectedWalletId === "here-wallet") {
const hereKeystore = ls.get("herewallet:keystore");
Expand Down
4 changes: 3 additions & 1 deletion src/lib/data/near.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ async function web4ViewCall(contractId, methodName, args, fallback) {
/**
* Current VM Features:
* - enableComponentSrcDataKey: Allows enabling the component source `data-component` attribute for rendered DOM elements. Disabled by default.
**/
* - enableComponentPropsDataKey: Allows enabling the component props `data-props` attribute for rendered DOM elements. Disabled by default.
* - skipTxConfirmationPopup: Disables pop-ups that require the user to confirm each transaction. Disabled by default.
*/
async function _initNear({
networkId,
config,
Expand Down
25 changes: 14 additions & 11 deletions src/lib/vm/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,9 @@ class VmStack {
: requireJSXIdentifierOrMemberExpression(code.openingElement.name);
let withChildren = ApprovedTags[element];
let customElement = null;
if (withChildren === undefined) {
if (this.vm.near.config.customElements.hasOwnProperty(element)) {
withChildren = true;
customElement = this.vm.near.config.customElements[element];
}
if (this.vm.near.config.customElements.hasOwnProperty(element)) {
withChildren = true;
customElement = this.vm.near.config.customElements[element];
}
const RadixComp = assertRadixComponent(element);

Expand Down Expand Up @@ -649,11 +647,6 @@ class VmStack {
attributes.key =
attributes.key ?? `${this.vm.widgetSrc}-${element}-${this.vm.gIndex}`;

if (this.vm.near?.features?.enableComponentSrcDataKey == true) {
attributes["data-component"] =
attributes["data-component"] ?? this.vm.widgetSrc;
}

delete attributes.dangerouslySetInnerHTML;
delete attributes.is;
const basicElement =
Expand Down Expand Up @@ -2303,7 +2296,17 @@ export default class VM {
return <div className="alert alert-danger">{message}</div>;
}

const result = this.execCode(args);
let result = this.execCode(args);

if (this.near.features?.enableComponentPropsDataKey && isReactObject(result)) {
result = { ...result };
result.props = { ...result.props, "data-props": JSON.stringify(args.props) };
}

if (this.near.features?.enableComponentSrcDataKey && isReactObject(result)) {
result = { ...result };
result.props = { ...result.props, "data-component": this.widgetSrc };
}

return isReactObject(result) ||
typeof result === "string" ||
Expand Down
6 changes: 6 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ module.exports = function (env) {
amd: "react-dom",
root: "ReactDOM",
},
"styled-components": {
commonjs: "styled-components",
commonjs2: "styled-components",
amd: "styled-components",
root: "StyledComponents",
}
},
],
module: {
Expand Down
Loading