mirror of
https://github.com/fluencelabs/examples
synced 2025-06-12 01:21:20 +00:00
Add curl_template
This commit is contained in:
199
curl_template/frontend/src/components/App.scss
Normal file
199
curl_template/frontend/src/components/App.scss
Normal file
@ -0,0 +1,199 @@
|
||||
$bg-color1: white;
|
||||
$bg-color2: #f4f4f4;
|
||||
$font-color1: black;
|
||||
$color-disabled: lightgray;
|
||||
|
||||
$color1: black;
|
||||
$color2: rgb(214, 214, 214);
|
||||
|
||||
$accent-color: rgb(225, 30, 90);
|
||||
|
||||
$header-height: 60px;
|
||||
$border-radius: 10px;
|
||||
|
||||
@mixin font($size) {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
font-size: $size;
|
||||
}
|
||||
|
||||
$shadow: 0px 5px 20px rgba(0, 0, 0, 0.1);
|
||||
|
||||
body {
|
||||
background-color: $bg-color2;
|
||||
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
}
|
||||
|
||||
.header-wrapper {
|
||||
padding: 0 20px;
|
||||
height: $header-height;
|
||||
|
||||
background-color: $bg-color1;
|
||||
color: $font-color1;
|
||||
|
||||
box-shadow: $shadow;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
width: 1200px;
|
||||
height: 100%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
|
||||
@media (max-width: 1280px) {
|
||||
width: calc(100vw - 80px);
|
||||
margin-left: 20px;
|
||||
margin-right: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 1700px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding-top: 50px;
|
||||
|
||||
@media (max-width: 1280px) {
|
||||
width: calc(100vw - 80px);
|
||||
margin-left: 35px;
|
||||
margin-right: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
.text-input {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
padding: 0 15px;
|
||||
box-sizing: border-box;
|
||||
|
||||
margin-top: 5px;
|
||||
border: none;
|
||||
|
||||
font-style: normal;
|
||||
@include font(15px);
|
||||
color: $color1;
|
||||
|
||||
box-shadow: $shadow;
|
||||
|
||||
&::placeholder {
|
||||
color: $color2;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
outline: 1px solid white;
|
||||
border: 1px solid $accent-color;
|
||||
}
|
||||
}
|
||||
|
||||
.button {
|
||||
display: inline;
|
||||
width: 100px;
|
||||
height: 40px;
|
||||
|
||||
box-sizing: border-box;
|
||||
background-color: white;
|
||||
|
||||
margin-top: 10px;
|
||||
margin-right: 10px;
|
||||
border: none;
|
||||
|
||||
font-style: normal;
|
||||
@include font(15px);
|
||||
color: $color1;
|
||||
|
||||
box-shadow: $shadow;
|
||||
|
||||
&::placeholder {
|
||||
color: $color2;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
outline: 1px solid white;
|
||||
border: 1px solid $accent-color;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
color: gray;
|
||||
}
|
||||
}
|
||||
|
||||
.form-caption {
|
||||
color: $accent-color;
|
||||
text-align: center;
|
||||
|
||||
font-style: normal;
|
||||
font-weight: bold;
|
||||
@include font(20px);
|
||||
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.header-item {
|
||||
@include font(14px);
|
||||
text-transform: uppercase;
|
||||
|
||||
& button {
|
||||
@include font(14px);
|
||||
text-transform: uppercase;
|
||||
|
||||
background: none;
|
||||
border-top: none;
|
||||
border-right: none;
|
||||
border-left: none;
|
||||
border-bottom: 1px solid $accent-color;
|
||||
text-decoration: none;
|
||||
|
||||
outline: none;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: $accent-color;
|
||||
border-bottom: 2px solid $accent-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.green {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.accent {
|
||||
color: $accent-color;
|
||||
}
|
||||
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
width: 100%;
|
||||
min-height: 800px;
|
||||
margin-top: 50px;
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
background-color: white;
|
||||
|
||||
box-shadow: $shadow;
|
||||
}
|
||||
|
||||
th {
|
||||
@include font(18px);
|
||||
min-width: 100px;
|
||||
border-bottom: 20px solid transparent;
|
||||
}
|
||||
|
||||
td {
|
||||
@include font(14px);
|
||||
border-left: 15px solid transparent;
|
||||
border-right: 15px solid transparent;
|
||||
}
|
93
curl_template/frontend/src/components/App.tsx
Normal file
93
curl_template/frontend/src/components/App.tsx
Normal file
@ -0,0 +1,93 @@
|
||||
import { createClient, FluenceClient } from '@fluencelabs/fluence';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
relayNode,
|
||||
curlRequest
|
||||
} from 'src/fluence';
|
||||
|
||||
import './App.scss';
|
||||
|
||||
const App = () => {
|
||||
const [client, setClient] = useState<FluenceClient | null>(null);
|
||||
const [url, setUrl] = useState('https://api.duckduckgo.com/?q=homotopy&format=json');
|
||||
const [data, setData] = useState<{url: String, response: String}[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fn = async () => {
|
||||
try {
|
||||
const client = await createClient(relayNode);
|
||||
setClient(client);
|
||||
} catch (err) {
|
||||
console.log('Client initialization failed', err);
|
||||
}
|
||||
};
|
||||
fn();
|
||||
}, []);
|
||||
|
||||
const request = async () => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
let response = await curlRequest(client, url, 10000);
|
||||
setData((prev) => [...prev, { url, response }]);
|
||||
};
|
||||
|
||||
const stop = async () => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="header-wrapper">
|
||||
<div className="header">
|
||||
<div className="header-item"></div>
|
||||
|
||||
<div className="header-item">
|
||||
Connection status: {client ? <span className="accent">connected</span> : 'disconnected'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="content">
|
||||
<div>Url. e.g: https://google.com</div>
|
||||
<div>
|
||||
<input
|
||||
className="text-input"
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
type="text"
|
||||
value={url}
|
||||
/>
|
||||
</div>
|
||||
<div className="buttons">
|
||||
<button disabled={!url} className="button" onClick={request}>
|
||||
request
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="table-wrapper">
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Request log.</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map(({url, response}, idx) => (
|
||||
<tr>
|
||||
<td className="td1">{url}</td>
|
||||
<td className="td2">{response}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
34
curl_template/frontend/src/fluence.ts
Normal file
34
curl_template/frontend/src/fluence.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { FluenceClient, Particle, sendParticleAsFetch } from '@fluencelabs/fluence';
|
||||
import { testNet } from '@fluencelabs/fluence-network-environment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export const relayNode = testNet[3];
|
||||
const node = relayNode.peerId;
|
||||
|
||||
const serviceId = 'e90bfbaf-ede7-4fbe-b45a-6250bf36ed3e';
|
||||
|
||||
export const curlRequest = async (client: FluenceClient, url: String, ttl: number) => {
|
||||
const script = `
|
||||
(seq
|
||||
(call myRelay ("op" "identity") [])
|
||||
(seq
|
||||
(call node (serviceId "request") [url] result)
|
||||
(seq
|
||||
(call myRelay ("op" "identity") [])
|
||||
(call myPeerId ("_callback" callback) [result])
|
||||
)
|
||||
)
|
||||
)
|
||||
`;
|
||||
|
||||
let callbackId = uuidv4();
|
||||
const data = new Map();
|
||||
data.set('node', node);
|
||||
data.set('serviceId', serviceId);
|
||||
data.set('myRelay', client.relayPeerId);
|
||||
data.set('myPeerId', client.selfPeerId);
|
||||
data.set('callback', callbackId);
|
||||
data.set('url', url);
|
||||
|
||||
return await sendParticleAsFetch<String>(client, new Particle(script, data, ttl), callbackId);
|
||||
};
|
144
curl_template/frontend/src/index.scss
Normal file
144
curl_template/frontend/src/index.scss
Normal file
@ -0,0 +1,144 @@
|
||||
/* http://meyerweb.com/eric/tools/css/reset/
|
||||
v2.0 | 20110126
|
||||
License: none (public domain)
|
||||
*/
|
||||
|
||||
html,
|
||||
body,
|
||||
div,
|
||||
span,
|
||||
applet,
|
||||
object,
|
||||
iframe,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p,
|
||||
blockquote,
|
||||
pre,
|
||||
a,
|
||||
abbr,
|
||||
acronym,
|
||||
address,
|
||||
big,
|
||||
cite,
|
||||
code,
|
||||
del,
|
||||
dfn,
|
||||
em,
|
||||
img,
|
||||
ins,
|
||||
kbd,
|
||||
q,
|
||||
s,
|
||||
samp,
|
||||
small,
|
||||
strike,
|
||||
strong,
|
||||
sub,
|
||||
sup,
|
||||
tt,
|
||||
var,
|
||||
b,
|
||||
u,
|
||||
i,
|
||||
center,
|
||||
dl,
|
||||
dt,
|
||||
dd,
|
||||
ol,
|
||||
ul,
|
||||
li,
|
||||
fieldset,
|
||||
form,
|
||||
label,
|
||||
legend,
|
||||
table,
|
||||
caption,
|
||||
tbody,
|
||||
tfoot,
|
||||
thead,
|
||||
tr,
|
||||
th,
|
||||
td,
|
||||
article,
|
||||
aside,
|
||||
canvas,
|
||||
details,
|
||||
embed,
|
||||
figure,
|
||||
figcaption,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
output,
|
||||
ruby,
|
||||
section,
|
||||
summary,
|
||||
time,
|
||||
mark,
|
||||
audio,
|
||||
video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
figcaption,
|
||||
figure,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
ol,
|
||||
ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
blockquote,
|
||||
q {
|
||||
quotes: none;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
&:before,
|
||||
&:after {
|
||||
content: '';
|
||||
content: none;
|
||||
}
|
||||
}
|
||||
|
||||
q {
|
||||
&:before,
|
||||
&:after {
|
||||
content: '';
|
||||
content: none;
|
||||
}
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
14
curl_template/frontend/src/index.tsx
Normal file
14
curl_template/frontend/src/index.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.scss';
|
||||
import App from './components/App';
|
||||
import log from 'loglevel';
|
||||
|
||||
log.setLevel('error');
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root'),
|
||||
);
|
1
curl_template/frontend/src/react-app-env.d.ts
vendored
Normal file
1
curl_template/frontend/src/react-app-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
5
curl_template/frontend/src/setupTests.ts
Normal file
5
curl_template/frontend/src/setupTests.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
Reference in New Issue
Block a user