Skip to content

Commit

Permalink
Update Staking UI (hacky)
Browse files Browse the repository at this point in the history
Request parsing should happen in SignStakingApi, not ad-hoc in the UI logic.
  • Loading branch information
sisou committed Nov 19, 2024
1 parent 7229e6a commit 30e22f4
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 145 deletions.
5 changes: 5 additions & 0 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export type SignStakingRequest = SimpleRequest & {
transaction: Uint8Array | Uint8Array[], // An array is only allowed for retire_stake + remove_stake transactions
senderLabel?: string,
recipientLabel?: string,
validatorAddress?: string,
validatorImageUrl?: string,
fromValidatorAddress?: string,
fromValidatorImageUrl?: string,
amount?: number,
};

export type SignBtcTransactionRequestStandard = SimpleRequest & BitcoinTransactionInfo & {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/RequestParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class RequestParser { // eslint-disable-line no-unused-vars
*/
_parseUrl(url, parameterName) {
const parsedUrl = new URL(url);
const whitelistedProtocols = ['https:', 'http:', 'chrome-extension:', 'moz-extension:'];
const whitelistedProtocols = ['https:', 'http:', 'chrome-extension:', 'moz-extension:', 'data:'];
if (!whitelistedProtocols.includes(parsedUrl.protocol)) {
const protocolString = whitelistedProtocols.join(', ');
throw new Errors.InvalidRequestError(`${parameterName} protocol must be one of: ${protocolString}`);
Expand Down
7 changes: 0 additions & 7 deletions src/request/sign-staking/SignStaking.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,3 @@
opacity: 0.5;
margin-bottom: 0.25rem;
}

#confirm-staking .data-section {
margin: 1rem 3rem;
text-align: center;
max-width: 100%;
overflow-wrap: break-word;
}
297 changes: 164 additions & 133 deletions src/request/sign-staking/SignStaking.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/request/sign-staking/SignStakingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ class SignStakingApi extends TopLevelApi { // eslint-disable-line no-unused-vars
}
}

if (request.validatorAddress) {
parsedRequest.validatorAddress = this.parseAddress(request.validatorAddress, 'validatorAddress', false);
}

if (request.validatorImageUrl) {
parsedRequest.validatorImageUrl = this._parseUrl(request.validatorImageUrl, 'validatorImageUrl');
}

if (request.fromValidatorAddress) {
parsedRequest.validatorAddress = this.parseAddress(
request.fromValidatorAddress,
'fromValidatorAddress',
false,
);
}

if (request.fromValidatorImageUrl) {
parsedRequest.fromValidatorImageUrl = this._parseUrl(request.fromValidatorImageUrl, 'fromValidatorImageUrl');
}

if (request.amount) {
parsedRequest.amount = this.parseNonNegativeFiniteNumber(request.amount, true, 'amount');
}

return parsedRequest;
}

Expand Down
4 changes: 1 addition & 3 deletions src/request/sign-staking/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</div>
<div id="effect-container">
<div class="page-header nq-card-header">
<h1 data-i18n="sign-tx-heading-tx" class="nq-h1">Confirm Transaction</h1>
<h1 id="headline" class="nq-h1"></h1>
</div>

<div class="page-body nq-card-body transaction">
Expand All @@ -102,8 +102,6 @@ <h1 data-i18n="sign-tx-heading-tx" class="nq-h1">Confirm Transaction</h1>
<div class="fee-section nq-text-s display-none">
+ <span id="fee"></span> <span class="nim-symbol"></span> <span data-i18n="sign-tx-fee">fee</span>
</div>

<div class="data-section display-none nq-text nq-blue" id="data"></div>
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "Gebühr",
"sign-tx-cancel-payment": "Zahlung abbrechen",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Nachricht signieren",
"sign-msg-signer": "Unterzeichner",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "fee",
"sign-tx-cancel-payment": "Cancel payment",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Sign Message",
"sign-msg-signer": "Signer",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "cuota",
"sign-tx-cancel-payment": "Cancelar pago",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Firmar Mensaje",
"sign-msg-signer": "Firmador",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "frais",
"sign-tx-cancel-payment": "Annuler le paiement",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Signer le Message",
"sign-msg-signer": "Signataire",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "kosten",
"sign-tx-cancel-payment": "Annuleer betaling",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Bericht ondertekenen",
"sign-msg-signer": "Ondertekenaar",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "taxa",
"sign-tx-cancel-payment": "Cancelar pagamento",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Assinar Mensagem",
"sign-msg-signer": "Signatário",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "комиссия",
"sign-tx-cancel-payment": "Отменить платёж",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Подписать сообщение",
"sign-msg-signer": "Отправитель",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "комісія",
"sign-tx-cancel-payment": "Скасувати платіж",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "Підписати повідомлення",
"sign-msg-signer": "Підписант",

Expand Down
4 changes: 4 additions & 0 deletions src/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"sign-tx-fee": "手续费",
"sign-tx-cancel-payment": "取消付款",

"sign-staking-heading-stake": "Stake NIM",
"sign-staking-heading-unstake": "Unstake NIM",
"sign-staking-heading-change": "Change Validator",

"sign-msg-heading": "签署信息",
"sign-msg-signer": "签署者",

Expand Down
8 changes: 7 additions & 1 deletion types/Keyguard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ type Parsed<T extends KeyguardRequest.Request> =
T extends Is<T, KeyguardRequest.SignStakingRequest> ?
Transform<KeyId2KeyInfo<KeyguardRequest.SignStakingRequest> & {
plain: Nimiq.PlainTransaction[],
}, 'transaction', { transactions: Nimiq.Transaction[] }> :
}, 'transaction' | 'validatorAddress' | 'validatorImageUrl' | 'fromValidatorAddress' | 'fromValidatorImageUrl', {
transactions: Nimiq.Transaction[],
validatorAddress?: Nimiq.Address,
validatorImageUrl?: URL,
fromValidatorAddress?: Nimiq.Address,
fromValidatorImageUrl?: URL,
}> :
T extends Is<T, KeyguardRequest.SignMessageRequest> ?
Transform<
KeyId2KeyInfo<KeyguardRequest.SignMessageRequest>,
Expand Down

0 comments on commit 30e22f4

Please sign in to comment.