Merge pull request #130 from richard-ramos/feat/css

This commit is contained in:
fryorcraken.eth 2022-10-07 11:38:11 +11:00 committed by GitHub
commit bdc6e9cb93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 138 additions and 46 deletions

1
ci/Jenkinsfile vendored
View File

@ -80,4 +80,5 @@ def buildExample(example=STAGE_NAME) {
def copyExample(example=STAGE_NAME) { def copyExample(example=STAGE_NAME) {
sh "mkdir -p build/docs/${example}" sh "mkdir -p build/docs/${example}"
sh "cp ${example}/index.html build/docs/${example}/" sh "cp ${example}/index.html build/docs/${example}/"
sh "[ -f ${example}/style.css ] && cp ${example}/style.css build/docs/${example}/"
} }

View File

@ -5,64 +5,102 @@
<meta charset='UTF-8'/> <meta charset='UTF-8'/>
<meta content='width=device-width, initial-scale=1.0' name='viewport'/> <meta content='width=device-width, initial-scale=1.0' name='viewport'/>
<title>JS-Waku light node example</title> <title>JS-Waku light node example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<div><h1>Waku RLN</h1> <div class="row rcenter">
<div><span id='status'></span></div> <h1>Waku RLN</h1>
<div><h2>Blockchain</h2> <button id='connect-wallet' type='button'>Connect Wallet</button>
<div><h3>Wallet</h3>
<p>Address: <span id='address'></span></p>
<button id='connect-wallet' type='button'>Connect Wallet</button>
</div>
<div><h3>Contract Data</h3>
<p>Latest membership id on contract: <span id='latest-membership-id'></span></p>
<button disabled id='retrieve-rln-details' type='button'>Retrieve contract state from blockchain
</button>
</div>
</div> </div>
<div><h2>Credentials</h2> <span id='status'></span>
<p>You can either generate new credentials:</p>
<button disabled id='generate-credentials' type='button'>Generate RLN Credentials</button>
<p>Or import existing ones:</p>
<label for="membership-id">Membership ID (your index in the RLN smart contract):</label>
<input id="membership-id" name="membership-id" type="text"><br>
<label for="id-key">RLN Identity Key (hex string):</label>
<input id="id-key" name="id-key" type="text"><br>
<label for="commitment-key">RLN Commitment Key (hex string):</label>
<input id="commitment-key" name="commitment-key" type="text"><br>
<button disabled id='import-button' type='button'>Import RLN Credentials</button>
<p><strong>Membership id: </strong><span id="id">none</span></p> <h2 class="mu1">Blockchain</h2>
<p><strong>Key: </strong><span id="key">none</span></p> <hr />
<p><strong>Commitment: </strong><span id="commitment">none</span></p>
<button disabled id='register-button' type='button'>Register Credentials in Contract</button> <div class="row rcenter">
<h4>Address</h4>
<code id="address" class="value"></code>
</div> </div>
<div><h1>Waku</h1> <div class="row mu1 rcenter">
<div id="waku-status"></div> <h4>Contract Data</h4>
<button disabled id='retrieve-rln-details' type='button'>
Retrieve contract state from blockchain
</button>
</div>
<div class="row rcenter">
<h4>Latest membership id on contract</h4>
<code id="latest-membership-id" class="value">Not loaded yet</code>
</div>
<h2 class="mu1">Credentials</h2>
<hr />
<div class="row">
<div class="w50">
<h4>You can either generate new credentials:</h4>
<button disabled id='generate-credentials' type='button'>Generate RLN Credentials</button>
<br />
<br />
<button disabled id='register-button' type='button'>Register Credentials in Contract</button>
</div>
<div class="w50">
<h4>Or import existing ones:</h4>
<label for="membership-id">Membership ID (your index in the RLN smart contract):</label>
<input id="membership-id" name="membership-id" type="text" />
<label for="id-key">RLN Identity Key (hex string):</label>
<input id="id-key" name="id-key" type="text" />
<label for="commitment-key">RLN Commitment Key (hex string):</label>
<input id="commitment-key" name="commitment-key" type="text" />
<button disabled id='import-button' type='button'>Import RLN Credentials</button>
</div>
</div>
<div class="row rcenter mu1">
<h4>Membership id</h4>
<code id="id" class="value">none</code>
</div>
<div class="row rcenter">
<h4>Key</h4>
<code id="key" class="value">none</code>
</div>
<div class="row rcenter">
<h4>Commitment</h4>
<code id="commitment" class="value">none</code>
</div>
<h2 class="mu1">Waku</h2>
<hr />
<div id="waku-status"></div>
<div class="row rcenter mu1 mf">
<label for='remote-multiaddr'>Remote peer's multiaddr</label> <label for='remote-multiaddr'>Remote peer's multiaddr</label>
<input id='remote-multiaddr' <input id='remote-multiaddr'
type='text' type='text'
value="/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm"> value="/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm">
<button disabled id='dial' type='button'>Dial</button> <button disabled id='dial' type='button'>Dial</button>
<br/>
<label for='nick-input'>Your nickname</label>
<input id='nick-input' placeholder='Choose a nickname' type='text'>
<br/>
<label for='textInput'>Message text</label>
<input disabled id='textInput' placeholder='Type your message here' type='text'>
<button disabled id='sendButton' type='button'>Send message using Light Push</button>
<span id='sending-status'></span>
<br/>
<div id="messages"></div>
</div> </div>
</div>
<div class="row rcenter mf">
<label for='nick-input'>Your nickname</label>
<input id='nick-input' placeholder='Choose a nickname' type='text' class="p100">
</div>
<div class="row rcenter mf">
<label for='textInput'>Message text</label>
<input disabled id='textInput' placeholder='Type your message here' type='text' class="p100">
<button disabled id='sendButton' type='button'>Send message using Light Push</button>
</div>
<span id='sending-status'></span>
<h4 class="mu1">Messages</h4>
<div id="messages"></div>
<script type='module'> <script type='module'>
import {utils} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/index.js'; import {utils} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/index.js';
@ -147,7 +185,7 @@
if (membershipKey) { if (membershipKey) {
keyDiv.innerHTML = utils.bytesToHex(membershipKey.IDKey) keyDiv.innerHTML = utils.bytesToHex(membershipKey.IDKey)
commitmentDiv.innerHTML = utils.bytesToHex(membershipKey.IDCommitment) commitmentDiv.innerHTML = utils.bytesToHex(membershipKey.IDCommitment)
idDiv.innerHTML = membershipId || "-" idDiv.innerHTML = membershipId || "not registered yet"
if (membershipId && rlnInstance) { if (membershipId && rlnInstance) {
encoder = new RLNEncoder( encoder = new RLNEncoder(
@ -173,7 +211,7 @@
dialButton.disabled = !(node && node.isStarted() && retrievedRLNEvents) dialButton.disabled = !(node && node.isStarted() && retrievedRLNEvents)
retrieveRLNDetailsButton.disabled = !rlnInstance && !retrievedRLNEvents; retrieveRLNDetailsButton.disabled = !rlnInstance || retrievedRLNEvents;
} }
// Blockchain // Blockchain
@ -227,6 +265,7 @@
latestMembershipSpan.innerText = indexInt latestMembershipSpan.innerText = indexInt
} }
console.debug("IDCommitment registered in tree", idCommitment, indexInt); console.debug("IDCommitment registered in tree", idCommitment, indexInt);
latestMembershipSpan.innerHTML = indexInt;
} catch (err) { } catch (err) {
console.error(err); // TODO: the merkle tree can be in a wrong state. The app should be disabled console.error(err); // TODO: the merkle tree can be in a wrong state. The app should be disabled
} }
@ -304,6 +343,7 @@
// Waku // Waku
nicknameInput.onchange = updateFields nicknameInput.onchange = updateFields
nicknameInput.onblur = updateFields;
let messages = []; let messages = [];
@ -351,7 +391,7 @@
} }
messages.push({ messages.push({
msg: `(${nick}) <strong>${utils.bytesToUtf8(text)}</strong> <i>[${time.toString()}]</i>`, msg: `(${nick}) <strong>${utils.bytesToUtf8(text)}</strong> <i>[${time.toISOString()}]</i>`,
epoch: wakuMessage.epoch, epoch: wakuMessage.epoch,
verify, verify,
proofState proofState

51
rln-js/style.css Normal file
View File

@ -0,0 +1,51 @@
html {
scroll-behavior: smooth;
}
h1 {
margin: 1rem 2.5rem 1rem 0;
}
.value {
font-size: 1.3em;
}
body > footer {
text-align: right;
}
.row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.rcenter {
align-items: center;
}
.mu1 {
margin-top: 4em;
}
.w50 {
width: 46%;
}
.w30 {
width: 35%;
}
.w70 {
width: 60%;
}
.mf label {
width: 100%;
}
.mf input {
width: 80%;
}
.mf input.p100 {
width: 100%;
}