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

Promo card Improvement #438

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions assets/icons/icon-gift-opened.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,20 @@ a {
margin-bottom: 6px;
}

.giftIcons svg {
height:16px;
fill:#7A7387;
position:relative;
top:-4px;
}

.giftIconsClosed svg {
height:16px;
fill:#9621FF;
position:relative;
top:-2px;
}

.textboxTransparency {
background-color: rgba(255, 255, 255, 15%);
color: #fff;
Expand Down
23 changes: 1 addition & 22 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -716,17 +716,6 @@ defineExpose({
>
<thead style="border: 0px">
<tr>
<td
style="
width: 100px;
border-top: 0px;
border-bottom: 1px
solid #534270;
"
class="text-center"
>
<b> Manage </b>
</td>
<td
style="
width: 100px;
Expand All @@ -751,22 +740,12 @@ defineExpose({
</td>
<td
style="
width: 100px;
border-top: 0px;
border-bottom: 1px
solid #534270;
"
class="text-center"
>
<b> State </b
><i
onclick="MPW.promosToCSV()"
style="
margin-left: 5px;
"
class="fa-solid fa-lg fa-file-csv ptr"
></i>
</td>
></td>
</tr>
</thead>
<tbody
Expand Down
60 changes: 38 additions & 22 deletions scripts/promos.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { deriveAddress } from './encoding.js';
import { getP2PKHScript } from './script.js';
import { createAlert } from './alerts/alert.js';

import pIconGift from '../assets/icons/icon-gift.svg';
import pIconGiftOpen from '../assets/icons/icon-gift-opened.svg';

/** The fee in Sats to use for Creating or Redeeming PIVX Promos */
export const PROMO_FEE = 10000;

Expand Down Expand Up @@ -369,7 +372,9 @@ export async function renderSavedPromos() {

// Sync only the balance of the code (not full data)
cCode.getUTXOs(false);
const nBal = (await cCode.getBalance(true)) / COIN;

let nBal = ((await cCode.getBalance(true)) - PROMO_FEE) / COIN;
nBal = nBal < 0 ? 0 : nBal;
BreadJS marked this conversation as resolved.
Show resolved Hide resolved

// A code younger than ~3 minutes without a balance will just say 'confirming', since Blockbook does not return a balance for NEW codes
const fNew = cCode.time.getTime() > Date.now() - 60000 * 3;
Expand All @@ -381,21 +386,21 @@ export async function renderSavedPromos() {
let strStatus = 'Confirming...';
if (!fNew) {
if (cCode.fSynced) {
strStatus = nBal > 0 ? 'Unclaimed' : 'Claimed';
strStatus =
nBal > 0
? '<span class="giftIconsClosed">' +
pIconGift +
'</span>'
: '<span class="giftIcons">' +
pIconGiftOpen +
'</span>';
} else {
strStatus = 'Syncing';
strStatus =
'<i class="fa-solid fa-spinner spinningLoading"></i>';
}
}
strHTML += `
<tr>
<td>${
fCannotDelete
? '<i class="fa-solid fa-ban" style="opacity: 0.4; cursor: default;">'
: '<i class="fa-solid fa-ban ptr" onclick="MPW.deletePromoCode(\'' +
cCode.code +
'\')"></i>'
}
</td>
<td><i onclick="MPW.toClipboard('copy${
cCode.address
}', this)" class="fas fa-clipboard" style="cursor: pointer; margin-right: 10px;"></i><code id="copy${
Expand All @@ -408,9 +413,17 @@ export async function renderSavedPromos() {
? '...'
: nBal + ' ' + cChainParams.current.TICKER
}</td>
<td><a class="ptr active" style="margin-right: 10px;" href="${
<td>
${
fCannotDelete
? '<i class="fa-solid fa-ban" style="opacity: 0.4; cursor: default;">'
: '<i class="fa-solid fa-ban ptr" onclick="MPW.deletePromoCode(\'' +
cCode.code +
'\')">'
}</i>
<a style="margin-left:6px; margin-right:6px; width:auto!important;" class="ptr active" href="${
getNetwork().strUrl + '/address/' + cCode.address
}" target="_blank" rel="noopener noreferrer"><i class="fa-solid fa-up-right-from-square"></i></a>${strStatus}</td>
}" target="_blank" rel="noopener noreferrer"><i class="fa-solid fa-up-right-from-square"></i></a><span style="margin-left:4px;">${strStatus}</span></td>
</tr>
`;
}
Expand Down Expand Up @@ -478,14 +491,15 @@ export async function updatePromoCreationTick(fRecursive = false) {
amount: Math.round(cThread.amount * COIN + PROMO_FEE),
}).catch((_) => {
// Failed to create this code - mark it as errored
cThread.end_state = 'Errored';
cThread.end_state =
'<i class="fas fa-exclamation-triangle"></i>';
});
if (res && res.ok) {
cThread.txid = res.txid;
cThread.end_state = 'Done';
cThread.end_state = '<i class="fas fa-check"></i>';
} else {
// If it looks like it was purposefully cancelled, then mark it as such
cThread.end_state = 'Cancelled';
cThread.end_state = '<i class="fas fa-times-circle"></i>';
}
}
}
Expand All @@ -494,14 +508,14 @@ export async function updatePromoCreationTick(fRecursive = false) {
let strState = '';
if (cThread.txid) {
// Complete state
strState = 'Confirming...';
strState = '<i class="fa-solid fa-spinner spinningLoading"></i>';
} else if (cThread.end_state) {
// Errored state (failed to broadcast, etc)
strState = cThread.end_state;
} else {
// Display progress
strState =
'<span id="c' +
'<i class="fa-solid fa-spinner spinningLoading" style="margin-right:4px;"></i> <span id="c' +
cThread.code +
'">' +
(cThread.thread.progress || 0) +
Expand All @@ -512,10 +526,12 @@ export async function updatePromoCreationTick(fRecursive = false) {
strHTML =
`
<tr>
<td><i class="fa-solid fa-ban ptr" onclick="MPW.deletePromoCode('${cThread.code}')"></i></td>
<td><code class="wallet-code active" style="display: inline !important;">${cThread.code}</code></td>
<td><code class="wallet-code active" style="display: inline !important; color: #e83e8c!important;">${cThread.code}</code></td>
<td>${cThread.amount} ${cChainParams.current.TICKER}</td>
<td>${strState}</td>
<td>
<i class="fa-solid fa-ban ptr" style="margin-right:4px;" onclick="MPW.deletePromoCode('${cThread.code}')"></i>
${strState}
</td>
</tr>
` + strHTML;
}
Expand Down Expand Up @@ -553,7 +569,7 @@ export async function updatePromoCreationTick(fRecursive = false) {
// After the update completes, await another update in one second
if (!fPromoIntervalStarted || fRecursive) {
fPromoIntervalStarted = true;
setTimeout(() => updatePromoCreationTick(true), 1000);
setTimeout(() => updatePromoCreationTick(true), 10000);
}
}

Expand Down
Loading