Skip to content

Commit

Permalink
Various PIVX Promos fixes (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSKitty authored Dec 14, 2024
1 parent 9237400 commit b66364f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
17 changes: 14 additions & 3 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../misc.js';
import { ALERTS, translation, tr } from '../i18n.js';
import { HardwareWalletMasterKey, HdMasterKey } from '../masterkey';
import { COIN } from '../chain_params';
import { COIN, cChainParams } from '../chain_params';
import { onMounted, ref, watch, computed } from 'vue';
import { getEventEmitter } from '../event_bus';
import { Database } from '../database';
Expand Down Expand Up @@ -791,7 +791,13 @@ defineExpose({
"
class="text-center"
>
<b> Amount </b>
<b>
{{
cChainParams
.current
.TICKER
}}
</b>
</td>
<td
style="
Expand All @@ -800,7 +806,12 @@ defineExpose({
solid #534270;
"
class="text-center"
></td>
>
<i
onclick="MPW.promosToCSV()"
class="fa-solid fa-lg fa-file-csv ptr"
></i>
</td>
</tr>
</thead>
<tbody
Expand Down
30 changes: 17 additions & 13 deletions scripts/promos.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ 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;

/** The maximum length of a rendered code before cutting off with a unicode ellipsis (…) */
const MAX_CODE_RENDER_LENGTH = 10;

/**
* The global storage for temporary Promo Code wallets, this is used for sweeping funds
* @type {PromoWallet}
Expand Down Expand Up @@ -196,9 +199,14 @@ export function promoConfirm() {
doms.domPromoTable.style.maxHeight = 'min-content';
}, 100);

// If the code is at least MAX_LENGTH, then we won't add security-randomness
const strCode = doms.domRedeemCodeCreateInput.value;
const fAddRandomness = strCode.length < MAX_CODE_RENDER_LENGTH;

createPromoCode(
doms.domRedeemCodeCreateInput.value,
Number(doms.domRedeemCodeCreateAmountInput.value)
strCode,
Number(doms.domRedeemCodeCreateAmountInput.value),
fAddRandomness
);
}
}
Expand Down Expand Up @@ -230,7 +238,7 @@ export async function createPromoCode(strCode, nAmount, fAddRandomness = true) {
const strFinalCode = fAddRandomness
? strCode
? strCode + '-' + getAlphaNumericRand(5).toUpperCase()
: getAlphaNumericRand(10).toUpperCase()
: getAlphaNumericRand(MAX_CODE_RENDER_LENGTH).toUpperCase()
: strCode;

// Ensure the amount is sane
Expand Down Expand Up @@ -391,8 +399,8 @@ export async function renderSavedPromos() {

// Trimmed code
const trimmedCode =
cCode.code.length > 10
? cCode.code.slice(0, 7) + '...'
cCode.code.length > MAX_CODE_RENDER_LENGTH
? cCode.code.slice(0, MAX_CODE_RENDER_LENGTH - 1) + ''
: cCode.code;

// Status calculation (defaults to 'fNew' condition)
Expand Down Expand Up @@ -421,11 +429,7 @@ export async function renderSavedPromos() {
)}" style="display: inline !important; color: #e83e8c;">${sanitizeHTML(
trimmedCode
)}</code></td>
<td>${
fNew || !cCode.fSynced
? '...'
: nBal + ' ' + cChainParams.current.TICKER
}</td>
<td>${fNew || !cCode.fSynced ? '...' : nBal}</td>
<td>
${
fCannotDelete
Expand Down Expand Up @@ -542,16 +546,16 @@ export async function updatePromoCreationTick(fRecursive = false) {

// Trimmed code
const trimmedCode =
cThread.code.length > 10
? cThread.code.slice(0, 7) + '...'
cThread.code.length > MAX_CODE_RENDER_LENGTH
? cThread.code.slice(0, MAX_CODE_RENDER_LENGTH - 1) + ''
: cThread.code;

// Render the table row
strHTML =
`
<tr>
<td><code class="wallet-code active" style="display: inline !important; color: #e83e8c!important;">${trimmedCode}</code></td>
<td>${cThread.amount} ${cChainParams.current.TICKER}</td>
<td>${cThread.amount}</td>
<td>
<i class="fa-solid fa-ban ptr" style="margin-right:4px;" onclick="MPW.deletePromoCode('${cThread.code}')"></i>
${strState}
Expand Down

0 comments on commit b66364f

Please sign in to comment.