Skip to content

Commit

Permalink
feat: added desktop notification
Browse files Browse the repository at this point in the history
  • Loading branch information
uZhW8Rgl committed Mar 13, 2024
1 parent c621169 commit 32f0874
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 12 deletions.
33 changes: 33 additions & 0 deletions contractConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import dotenv from "dotenv";
dotenv.config();

const contractConfig = {
rpcUrl: "https://rpc.ghostnet.teztnets.com/",
adminAddress: process.env.ADMIN_ADDRESS
? process.env.ADMIN_ADDRESS
: "tz1Na21NimuuPXcQdHUk2en2XWYe9McyDDgZ",
assetAddress: process.env.ASSET_ADDRESS
? process.env.ASSET_ADDRESS
: "KT1N3iJne4jFnQz4tdHBz5q7Cd8Wmd6XtZSH",
policyAddress: process.env.POLICY_ADDRESS
? process.env.POLICY_ADDRESS
: "KT1J7FvNLo2yQSUm7jcm2wzNHDBhR19Y5dJ9",
contractAddress: process.env.CONTRACT_ADDRESS
? process.env.CONTRACT_ADDRESS
//: "KT1QzJR59dvx3pHaCgLUoffSTMKqqHZEYTkh",
: "KT1QDheV2TkL3mitzYNKzunWYhSe6MmEPTh5",
verifiableCredentialsAddress: process.env.VERIFIABLE_CREDENTIALS_ADDRESS
? process.env.VERIFIABLE_CREDENTIALS_ADDRESS
: "KT1XgUq6rzN9q6YMh44TbLffEz3zb54HbY2H",
transferAddress: process.env.TRANSFER_ADDRESS
? process.env.TRANSFER_ADDRESS
: "KT18pEHAbmtGj9iYQAJNhN2CtzjBGf4zBxKX",
agreementAddress: process.env.AGREEMENT_ADDRESS
? process.env.AGREEMENT_ADDRESS
: "KT19Jk6zvWfFjWMVSozPNm7VDMKSDVGrU6XD",
agreementLoggingAddress: process.env.AGREEMENT_LOGGING_ADDRESS
? process.env.AGREEMENT_LOGGING_ADDRESS
: "KT1CHo3f2eWcnT7zCYs1KD1ERVXwEPYacj3A",
};

export { contractConfig };
47 changes: 38 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@think-it-labs/edc-connector-client": "^0.2.0-beta-6",
"express": "^4.18.3",
"rxjs": "~7.8.1",
"ws": "^8.16.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
Expand Down
26 changes: 24 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const express = require('express');
/*const express = require('express');
const app = express();
app.use(express.json());
Expand All @@ -8,4 +8,26 @@ app.post('/webhook', (req, res) => {
res.sendStatus(200);
});
app.listen(3005, () => console.log('Server listening on port 3005'));// chnage later to docker varible
app.listen(3005, () => console.log('Server listening on port 3005'));// chnage later to docker varible
*/
const express = require('express');
const http = require('http');
const WebSocket = require('ws');

const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });

app.use(express.json());

app.post('/webhook', (req, res) => {
console.log('Webhook received:', req.body);
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(req.body));
}
});
res.sendStatus(200);
});

server.listen(3005, () => console.log('Server listening on port 3005'));
41 changes: 41 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,46 @@
</head>
<body class="mat-typography">
<app-root></app-root>
<script>
import { contractConfig } from "../contractConfig.js";
const socket = new WebSocket('ws://localhost:3005');

socket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
notify(data);
});

if ("Notification" in window) {
if (Notification.permission === 'granted') {
notify();
} else {
Notification.requestPermission().then((res) => {
if (res === 'granted'){
notify();
} else if (res === 'denied') {
console.log("Notifications access denied");
} else if (res === 'default') {
console.log("Notification permission not given");
}
})
}
} else {
console.error("Notification not supported");
}

function notify(data) {
const notification = new Notification("New Contract Definition found", {
body: 'Mint endpoint has been triggered on ' + contractConfig.contractAddress
});

notification.addEventListener('click', () => {
window.open('https://better-call.dev/ghostnet/' + contractConfig.contractAddress + '/tokens');
})

setTimeout(() => {
notification.close();
}, 10000)
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<mat-icon>add_circle_outline</mat-icon>
Create contract definition
</button>

</div>

<div fxLayout="row wrap" fxLayoutAlign="start start">
Expand Down

0 comments on commit 32f0874

Please sign in to comment.