Skip to content

Commit

Permalink
feat: add cash drawer control
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Aug 14, 2024
1 parent ff3e9d3 commit 4df3a17
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 0 deletions.
144 changes: 144 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,150 @@ <h1>Digital Cash Wallet</h1>
</label>

<button type="submit" onclick="sendDash(event)">Send DASH</button>

<hr />
<label
>Cash Drawer (<code data-id="cash-balance">0.0000</code>)
<small>denominated coins</small>
</label>
<table>
<thead>
<tr>
<th>Denom</th>
<th>Priority</th>
<th>Have</th>
<th>Want</th>
<th>Need</th>
</tr>
</thead>
<tbody data-id="coins-table">
<tr data-denom="1000010000">
<th>10.000<span hidden>10000</span></th>
<th>
<input
name="priority"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="1"
/>
</th>
<th>0</th>
<th>
<input
name="want"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="2"
/>
</th>
<th>0</th>
</tr>
<tr data-denom="100001000">
<th>1.000<span hidden>01000</span></th>
<th>
<input
name="priority"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="10"
/>
</th>
<th>0</th>
<th>
<input
name="want"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="10"
/>
</th>
<th>0</th>
</tr>
<tr data-denom="10000100">
<th>0.100<span hidden>00100</span></th>
<th>
<input
name="priority"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="10"
/>
</th>
<th>0</th>
<th>
<input
name="want"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="50"
/>
</th>
<th>0</th>
</tr>
<tr data-denom="1000010">
<th>0.010<span hidden>00010</span></th>
<th>
<input
name="priority"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="1"
/>
</th>
<th>0</th>
<th>
<input
name="want"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="20"
/>
</th>
<th>0</th>
</tr>
<tr data-denom="100001">
<th>0.001<span hidden>00001</span></th>
<th>
<input
name="priority"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="0"
/>
</th>
<th>0</th>
<th>
<input
name="want"
onkeyup="syncCashDrawer(event)"
type="number"
step="1"
min="0"
value="5"
/>
</th>
<th>0</th>
</tr>
</tbody>
</table>
</form>
</section>
<br />
Expand Down
91 changes: 91 additions & 0 deletions public/wallet-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,96 @@
renderCoins();
}

let defaultCjSlots = [
{
denom: 10000100000,
priority: 1,
have: 0,
want: 2,
need: 0,
},
{
denom: 100001000,
priority: 10,
have: 0,
want: 10,
need: 0,
},
{
denom: 10000100,
priority: 10,
have: 0,
want: 50,
need: 0,
},
{
denom: 1000010,
priority: 1,
have: 0,
want: 20,
need: 0,
},
{
denom: 100001,
priority: 0,
have: 0,
want: 5,
need: 0,
},
];
function getCashDrawer() {
let slots = dbGet('cash-drawer-control', []);
if (!slots.length) {
slots = defaultCjSlots.slice(0);
dbSet('cash-drawer-control', slots);
}
return slots;
}
window.syncCashDrawer = function (event) {
console.log('DEBUG syncCashDrawer');
let isDirty = false;

let slots = getCashDrawer();
for (let slot of slots) {
let $row = $(`[data-denom="${slot.denom}"]`);
console.log('DEBUG syncCashDrawer slot', slot, $row);

let priorityStr = $('[name=priority]', $row).value;
if (priorityStr) {
let priority = parseFloat(priorityStr);
if (slot.priority !== priority) {
console.log('DEBUG update priority', slot.priority, priority);
isDirty = true;
slot.priority = priority;
}
}

let wantStr = $('[name=want]', $row).value;
if (wantStr) {
let want = parseFloat(wantStr);
if (slot.want !== want) {
console.log('DEBUG update priority', slot.want, want);
isDirty = true;
slot.want = want;
}
}
}

if (isDirty) {
dbSet('cash-drawer-control', slots);
}

return true;
};
function renderCashDrawer() {
let slots = getCashDrawer();
for (let slot of slots) {
let $row = $(`[data-denom="${slot.denom}"]`);
$('[name=priority]', $row).value = slot.priority;
$('[name=want]', $row).value = slot.want;
}
}

async function updateDeltas(addrs) {
for (let address of addrs) {
let info = dbGet(address);
Expand Down Expand Up @@ -544,6 +634,7 @@
}

await init();
renderCashDrawer();
}

main().catch(function (err) {
Expand Down

0 comments on commit 4df3a17

Please sign in to comment.