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

feat: add commit button as a widget with zoid #133

Merged
merged 20 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ REACT_APP_META_TX_API_IDS_MAP={"testing-80001-0":{"protocol": "xxxxxx", "BOSON":


REACT_APP_MAGIC_API_KEY=
REACT_APP_INFURA_KEY=
REACT_APP_INFURA_KEY=
REACT_APP_WIDGETS_URL=https://widgets-test.on.fleek.co
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/>
<title>Boson widgets</title>
<script src="./scripts/zoid/zoid.js"></script>
<script src="./scripts/commit-button.js"></script>
<script src="%REACT_APP_WIDGETS_URL%/scripts/commit-button.js"></script>
albertfolch-redeemeum marked this conversation as resolved.
Show resolved Hide resolved
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/commit-button-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<head>
<script src="./zoid/zoid.js"></script>
<script src="../../scripts/commit-button.js"></script>
<script src="https://widgets-test.on.fleek.co/scripts/commit-button.js"></script>
<style>
html,
body {
Expand Down
31 changes: 13 additions & 18 deletions public/scripts/commit-button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-undef */

const scriptOrigin = getScriptOrigin();
// const scriptOrigin = "http://localhost:3006/#";
function getScriptOrigin() {
const scriptElCommitButton = document.querySelector(
'script[src$="/commit-button.js"]'
);
const src = scriptElCommitButton.getAttribute("src");
const url = new URL(src);
return `${url.origin}/#`;
}
const EVENT = {
RENDER: "zoid-render",
RENDERED: "zoid-rendered",
Expand Down Expand Up @@ -101,19 +110,9 @@ function containerTemplate(
return div;
}

function getOriginFromProps({ props }) {
return !props.configId || props.configId.startsWith("production")
? "https://widgets.bosonprotocol.io/#"
: props.configId.startsWith("staging")
? "https://widgets-staging.on.fleek.co/#"
: "https://widgets-test.on.fleek.co/#"; //"http://localhost:3006/#";
}

var CommitButton = zoid.create({
tag: "boson-commit-button",
url: ({ props }) => {
return `${getOriginFromProps({ props })}/commit-button`;
},
url: `${scriptOrigin}/commit-button`,
dimensions: { width: "100%", height: "40px" },
containerTemplate: function (args) {
return containerTemplate(
Expand All @@ -134,18 +133,14 @@ var CommitButton = zoid.create({

var CommitWidgetModal = zoid.create({
tag: "boson-commit-modal",
url: ({ props }) => {
return `${getOriginFromProps({ props })}/commit?props=1`;
},
url: `${scriptOrigin}/commit?props=1`,
dimensions: { width: "100%", height: "100%" },
containerTemplate
});

var PurchaseOverviewModal = zoid.create({
tag: "purchase-overview-modal",
url: ({ props }) => {
return `${getOriginFromProps({ props })}/purchase-overview`;
},
url: `${scriptOrigin}/purchase-overview`,
dimensions: { width: "100%", height: "100%" },
containerTemplate
});
Loading