Fix button and roundings

This commit is contained in:
AlphaX-Projects 2022-08-29 20:08:50 +02:00
parent 39b461d480
commit cb252c3fa7
5 changed files with 240 additions and 308 deletions

View File

@ -36,7 +36,7 @@
"electron-log": "4.4.8" "electron-log": "4.4.8"
}, },
"devDependencies": { "devDependencies": {
"electron": "19.0.14", "electron": "20.1.0",
"electron-builder": "23.3.3", "electron-builder": "23.3.3",
"electron-notarize": "1.2.1", "electron-notarize": "1.2.1",
"electron-packager": "16.0.0", "electron-packager": "16.0.0",
@ -45,4 +45,4 @@
"engines": { "engines": {
"node": ">=14.17.0" "node": ">=14.17.0"
} }
} }

View File

@ -9,6 +9,7 @@ import '@vaadin/icons';
import '../functional-components/side-menu.js'; import '../functional-components/side-menu.js';
import '../functional-components/side-menu-item.js'; import '../functional-components/side-menu-item.js';
import './start-minting.js'
class SidenavMenu extends connect(store)(LitElement) { class SidenavMenu extends connect(store)(LitElement) {
static get properties() { static get properties() {
@ -44,13 +45,6 @@ class SidenavMenu extends connect(store)(LitElement) {
border-top: 1px solid var(--border); border-top: 1px solid var(--border);
outline: none; outline: none;
} }
.start-minting-wrapper {
position: absolute;
bottom: 130px;
left: 50%;
transform: translateX(calc(-50% - 10px));
}
`, `,
]; ];
} }
@ -59,9 +53,7 @@ class SidenavMenu extends connect(store)(LitElement) {
super(); super();
this.urls = []; this.urls = [];
this.nodeType = ''; this.nodeType = '';
this.theme = localStorage.getItem('qortalTheme') this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light';
? localStorage.getItem('qortalTheme')
: 'light';
this.addressInfo = {}; this.addressInfo = {};
} }
@ -225,15 +217,15 @@ class SidenavMenu extends connect(store)(LitElement) {
</side-menu-item> </side-menu-item>
${this.renderNodeManagement()} ${this.renderNodeManagement()}
</side-menu-item> </side-menu-item>
<div style="margin-top: 20px;">
<start-minting></start-minting>
</div>
`; `;
} }
} }
renderNodeManagement() { renderNodeManagement() {
const checkNodeManagement = const checkNodeManagement = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
store.getState().app.nodeConfig.knownNodes[
store.getState().app.nodeConfig.node
];
if ((checkNodeManagement.enableManagement = true)) { if ((checkNodeManagement.enableManagement = true)) {
return html` return html`
<side-menu-item <side-menu-item

View File

@ -7,22 +7,19 @@ import { asyncReplace } from 'lit/directives/async-replace.js';
import '../functional-components/my-button.js'; import '../functional-components/my-button.js';
import { routes } from '../plugins/routes.js'; import { routes } from '../plugins/routes.js';
import "@material/mwc-button" import "@material/mwc-button"
import '@material/mwc-dialog' import '@material/mwc-dialog'
async function* countDown(count, callback) { async function* countDown(count, callback) {
while (count > 0) { while (count > 0) {
yield count--; yield count--;
await new Promise((r) => setTimeout(r, 1000)); await new Promise((r) => setTimeout(r, 1000));
if (count === 0) { if (count === 0) {
callback() callback()
} }
} }
} }
class StartMinting extends connect(store)(LitElement) { class StartMinting extends connect(store)(LitElement) {
static get properties() { static get properties() {
return { return {
@ -194,101 +191,86 @@ class StartMinting extends connect(store)(LitElement) {
} }
renderErrorMsg1() { renderErrorMsg1() {
return html`${translate("startminting.smchange1")}` return html`${translate("startminting.smchange1")}`
}
renderErrorMsg2() {
return html`${translate("startminting.smchange2")}`
}
renderErrorMsg3() {
return html`${translate("startminting.smchange3")}`
}
renderErrorMsg4() {
return html`${translate("startminting.smchange4")}`
}
async getMintingAcccounts() {
const myNode =
store.getState().app.nodeConfig.knownNodes[
store.getState().app.nodeConfig.node
];
const nodeUrl =
myNode.protocol + '://' + myNode.domain + ':' + myNode.port;
const url = `${nodeUrl}/admin/mintingaccounts`;
try {
const res = await fetch(url);
const mintingAccountData = await res.json();
this.mintingAccountData = mintingAccountData;
} catch (error) {
this.errorMsg = this.renderErrorMsg1();
} }
}
async changeStatus(value){ renderErrorMsg2() {
const myNode = return html`${translate("startminting.smchange2")}`
store.getState().app.nodeConfig.knownNodes[ }
store.getState().app.nodeConfig.node
];
const nodeUrl = renderErrorMsg3() {
myNode.protocol + '://' + myNode.domain + ':' + myNode.port; return html`${translate("startminting.smchange3")}`
this.status = value }
const publicAddress =
window.parent.reduxStore.getState().app?.selectedAddress
?.base58PublicKey;
// Check to see if a sponsorship key on a newly-level 1 minter exists. If it does, remove it.
const findMintingAccountFromOtherUser = this.mintingAccountData.find(
(ma) => !ma.publicKey.includes(publicAddress)
);
const removeMintingAccount = async (publicKey) => {
const url = `${nodeUrl}/admin/mintingaccounts?apiKey=${myNode.apiKey}`; renderErrorMsg4() {
return html`${translate("startminting.smchange4")}`
}
return await fetch(url, { async getMintingAcccounts() {
method: 'DELETE', const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
body: publicKey, const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port;
}); const url = `${nodeUrl}/admin/mintingaccounts`;
}; try {
const res = await fetch(url);
const mintingAccountData = await res.json();
const addMintingAccount = async (sponsorshipKeyValue) => { this.mintingAccountData = mintingAccountData;
const url = `${nodeUrl}/admin/mintingaccounts?apiKey=${myNode.apiKey}`; } catch (error) {
this.errorMsg = this.renderErrorMsg1();
return await fetch(url, {
method: 'POST',
body: sponsorshipKeyValue,
});
};
try {
if (
findMintingAccountFromOtherUser &&
findMintingAccountFromOtherUser?.publicKey[0]
) {
await removeMintingAccount(
findMintingAccountFromOtherUser?.publicKey[0]
);
} }
} catch (error) {
this.errorMsg = this.renderErrorMsg2();
return;
} }
try { async changeStatus(value){
await addMintingAccount(this.privateRewardShareKey); const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
routes.showSnackBar({ const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port;
data: translate('becomeMinterPage.bchange19'), this.status = value
}); const publicAddress = window.parent.reduxStore.getState().app?.selectedAddress ?.base58PublicKey;
this.status = 5;
this.getMintingAcccounts();
} catch (error) {
this.errorMsg = this.renderErrorMsg3();
return;
}
} // Check to see if a sponsorship key on a newly-level 1 minter exists. If it does, remove it.
const findMintingAccountFromOtherUser = this.mintingAccountData.find((ma) => !ma.publicKey.includes(publicAddress));
const removeMintingAccount = async (publicKey) => {
const url = `${nodeUrl}/admin/mintingaccounts?apiKey=${myNode.apiKey}`;
return await fetch(url, {
method: 'DELETE',
body: publicKey,
});
};
const addMintingAccount = async (sponsorshipKeyValue) => {
const url = `${nodeUrl}/admin/mintingaccounts?apiKey=${myNode.apiKey}`;
return await fetch(url, {
method: 'POST',
body: sponsorshipKeyValue,
});
};
try {
if (
findMintingAccountFromOtherUser &&
findMintingAccountFromOtherUser?.publicKey[0]
) {
await removeMintingAccount(
findMintingAccountFromOtherUser?.publicKey[0]
);
}
} catch (error) {
this.errorMsg = this.renderErrorMsg2();
return;
}
try {
await addMintingAccount(this.privateRewardShareKey);
routes.showSnackBar({
data: translate('becomeMinterPage.bchange19'),
});
this.status = 5;
this.getMintingAcccounts();
} catch (error) {
this.errorMsg = this.renderErrorMsg3();
return;
}
}
async confirmRelationship(){ async confirmRelationship(){
const myNode = const myNode =
@ -337,232 +319,193 @@ async confirmRelationship(){
interval = setInterval(getAnswer, 5000); interval = setInterval(getAnswer, 5000);
} }
renderStartMintingButton() { renderStartMintingButton() {
const myNode = const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
store.getState().app.nodeConfig.knownNodes[ const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port;
store.getState().app.nodeConfig.node const mintingAccountData = this.mintingAccountData;
]; const addressInfo = window.parent.reduxStore.getState().app.accountInfo.addressInfo
const address = window.parent.reduxStore.getState().app?.selectedAddress?.address;
const nonce = window.parent.reduxStore.getState().app?.selectedAddress?.nonce;
const publicAddress = window.parent.reduxStore.getState().app?.selectedAddress ?.base58PublicKey;
const findMintingAccount = mintingAccountData.find((ma) => ma.mintingAccount === address);
const isMinterButKeyMintingKeyNotAssigned = addressInfo?.error !== 124 && addressInfo?.level >= 1 && !findMintingAccount;
const nodeUrl = const makeTransactionRequest = async (lastRef) => {
myNode.protocol + '://' + myNode.domain + ':' + myNode.port; let mylastRef = lastRef;
let rewarddialog1 = get('transactions.rewarddialog1');
let rewarddialog2 = get('transactions.rewarddialog2');
let rewarddialog3 = get('transactions.rewarddialog3');
let rewarddialog4 = get('transactions.rewarddialog4');
const mintingAccountData = this.mintingAccountData; let myTxnrequest = await routes.transaction({
data: {
const addressInfo = window.parent.reduxStore.getState().app.accountInfo.addressInfo type: 38,
nonce: nonce,
const address = params: {
window.parent.reduxStore.getState().app?.selectedAddress?.address; recipientPublicKey: publicAddress,
percentageShare: 0,
const nonce = lastReference: mylastRef,
window.parent.reduxStore.getState().app?.selectedAddress?.nonce; rewarddialog1: rewarddialog1,
rewarddialog2: rewarddialog2,
const publicAddress = rewarddialog3: rewarddialog3,
window.parent.reduxStore.getState().app?.selectedAddress rewarddialog4: rewarddialog4,
?.base58PublicKey; },
const findMintingAccount = mintingAccountData.find((ma) =>
ma.mintingAccount === address
);
const isMinterButKeyMintingKeyNotAssigned =
addressInfo?.error !== 124 &&
addressInfo?.level >= 1 &&
!findMintingAccount;
const makeTransactionRequest = async (lastRef) => {
let mylastRef = lastRef;
let rewarddialog1 = get('transactions.rewarddialog1');
let rewarddialog2 = get('transactions.rewarddialog2');
let rewarddialog3 = get('transactions.rewarddialog3');
let rewarddialog4 = get('transactions.rewarddialog4');
let myTxnrequest = await routes.transaction({
data: {
type: 38,
nonce: nonce,
params: {
recipientPublicKey: publicAddress,
percentageShare: 0,
lastReference: mylastRef,
rewarddialog1: rewarddialog1,
rewarddialog2: rewarddialog2,
rewarddialog3: rewarddialog3,
rewarddialog4: rewarddialog4,
}, },
}, disableModal: true,
disableModal: true, });
}); return myTxnrequest;
return myTxnrequest; };
};
const getTxnRequestResponse = (txnResponse) => { const getTxnRequestResponse = (txnResponse) => {
let err6string = get('rewardsharepage.rchange21'); let err6string = get('rewardsharepage.rchange21');
if (txnResponse?.extraData?.rewardSharePrivateKey && (txnResponse?.data?.message?.includes('multiple') || txnResponse?.data?.message?.includes('SELF_SHARE_EXISTS'))) { if (txnResponse?.extraData?.rewardSharePrivateKey && (txnResponse?.data?.message?.includes('multiple') || txnResponse?.data?.message?.includes('SELF_SHARE_EXISTS'))) {
return err6string return err6string
} }
if (txnResponse.success === false && txnResponse.message) { if (txnResponse.success === false && txnResponse.message) {
throw (txnResponse); throw (txnResponse);
} else if ( } else if (
txnResponse.success === true && txnResponse.success === true &&
!txnResponse.data.error !txnResponse.data.error
) { ) {
return err6string; return err6string;
} else { } else {
throw (txnResponse); throw (txnResponse);
} }
}; };
const createSponsorshipKey = async () => { const createSponsorshipKey = async () => {
this.status = 1 this.status = 1
let lastRef = await getLastRef(); let lastRef = await getLastRef();
let myTransaction = await makeTransactionRequest(lastRef); let myTransaction = await makeTransactionRequest(lastRef);
getTxnRequestResponse(myTransaction); getTxnRequestResponse(myTransaction);
return myTransaction?.extraData?.rewardSharePrivateKey return myTransaction?.extraData?.rewardSharePrivateKey
}; };
const getLastRef = async () => {
const url = `${nodeUrl}/addresses/lastreference/${address}`;
const res = await fetch(url);
const data = await res.text();
return data;
};
const getLastRef = async () => { const startMinting = async () => {
const url = `${nodeUrl}/addresses/lastreference/${address}`; this.openDialogRewardShare = true
this.errorMsg = '';
const res = await fetch(url); try {
this.privateRewardShareKey = await createSponsorshipKey();
this.confirmRelationship(publicAddress)
} catch (error) {
console.log({ error })
this.errorMsg = error?.data?.message || this.renderErrorMsg4();
return;
}
};
const data = await res.text(); return html`
${isMinterButKeyMintingKeyNotAssigned ? html`
<div class="start-minting-wrapper">
<my-button label="${translate('becomeMinterPage.bchange18')}"
?isLoading=${false}
.onClick=${async () => {
await startMinting();
if (this.errorMsg) {
routes.showSnackBar({
data: this.errorMsg,
});
}
}}
>
</my-button>
</div>
return data; <!-- Dialog for tracking the progress of starting minting -->
};
const startMinting = async () => {
this.openDialogRewardShare = true
this.errorMsg = '';
try {
this.privateRewardShareKey = await createSponsorshipKey();
this.confirmRelationship(publicAddress)
} catch (error) {
console.log({ error })
this.errorMsg = error?.data?.message || this.renderErrorMsg4();
return;
}
};
return html`
${isMinterButKeyMintingKeyNotAssigned
? html`
<div class="start-minting-wrapper">
<my-button
label="${translate(
'becomeMinterPage.bchange18'
)}"
?isLoading=${false}
.onClick=${async () => {
await startMinting();
if (this.errorMsg) {
routes.showSnackBar({
data: this.errorMsg,
});
}
}}
></my-button>
</div>
<!-- Dialog for tracking the progress of starting minting -->
${this.openDialogRewardShare ? html`
${this.openDialogRewardShare ? html`
<div class="dialogCustom"> <div class="dialogCustom">
<div class="dialogCustomInner"> <div class="dialogCustomInner">
<div class="dialog-header" > <div class="dialog-header" >
<div class="row"> <div class="row">
<h1>In progress </h1> <div class=${`smallLoading marginLoader ${this.status > 3 && 'hide'}`}></div> <h1>In progress</h1>
</div> <div class=${`smallLoading marginLoader ${this.status > 3 && 'hide'}`}></div>
<hr />
</div>
<div class="dialog-container">
<ul>
<li class="row between">
<p>
1. ${translate("startminting.smchange5")}
</p>
<div class=${`smallLoading marginLoader ${this.status !== 1 && 'hide'}`}></div>
</li>
<li class=${`row between ${this.status < 2 && 'inactiveText'}`}>
<p>
2. ${translate("startminting.smchange6")}
</p>
<div class=${`smallLoading marginLoader ${this.status !== 2 && 'hide'}`}></div>
</li>
<li class=${`row between ${this.status < 3 && 'inactiveText'}`}>
<p>
3. ${translate("startminting.smchange7")}
</p>
<div class="row no-width">
<div class=${`smallLoading marginLoader marginRight ${this.status !== 3 && 'hide'}`} ></div> ${asyncReplace(this.timer)}
</div> </div>
</li> <hr />
</div>
<div class="dialog-container">
<ul>
<li class="row between">
<p>
1. ${translate("startminting.smchange5")}
</p>
<div class=${`smallLoading marginLoader ${this.status !== 1 && 'hide'}`}></div>
</li>
<li class=${`row between ${this.status < 4 && 'inactiveText'}`}> <li class=${`row between ${this.status < 2 && 'inactiveText'}`}>
<p> <p>
4. ${translate("startminting.smchange8")} 2. ${translate("startminting.smchange6")}
</p> </p>
<div class=${`smallLoading marginLoader ${this.status !== 4 && 'hide'}`}></div> <div class=${`smallLoading marginLoader ${this.status !== 2 && 'hide'}`}></div>
</li> </li>
<li class=${`row between ${this.status < 5 && 'inactiveText'}`}> <li class=${`row between ${this.status < 3 && 'inactiveText'}`}>
<p> <p>
5. ${translate("startminting.smchange9")} 3. ${translate("startminting.smchange7")}
</p> </p>
</li> <div class="row no-width">
</ul> <div class=${`smallLoading marginLoader marginRight ${this.status !== 3 && 'hide'}`} ></div> ${asyncReplace(this.timer)}
<div class="warning column"> </div>
<p> </li>
Warning: do not close the Qortal UI until completion!
</p>
<p class="message-error">${this.errorMsg}</p>
</div>
</div>
<div class="modalFooter">
${this.errorMsg || this.status === 5 ? html`
<mwc-button
slot="primaryAction"
@click=${() => {
this.openDialogRewardShare = false
this.errorMsg = ''
}} <li class=${`row between ${this.status < 4 && 'inactiveText'}`}>
class="red" <p>
> 4. ${translate("startminting.smchange8")}
${translate("general.close")} </p>
</mwc-button> <div class=${`smallLoading marginLoader ${this.status !== 4 && 'hide'}`}></div>
</li>
<li class=${`row between ${this.status < 5 && 'inactiveText'}`}>
<p>
5. ${translate("startminting.smchange9")}
</p>
</li>
</ul>
<div class="warning column">
<p>
Warning: do not close the Qortal UI until completion!
</p>
<p class="message-error">${this.errorMsg}</p>
</div>
</div>
<div class="modalFooter">
${this.errorMsg || this.status === 5 ? html`
<mwc-button
slot="primaryAction"
@click=${() => {
this.openDialogRewardShare = false
this.errorMsg = ''
}}
class="red"
>
${translate("general.close")}
</mwc-button>
` : '' } ` : '' }
</div> </div>
</div>
<!-- </mwc-dialog> -->
</div> </div>
` : ""} <!-- </mwc-dialog> -->
</div>
` ` : ""}
: ''} ` : ''}
`; `;
} }
stateChanged(state) { stateChanged(state) {
this.addressInfo = state.app.accountInfo.addressInfo; this.addressInfo = state.app.accountInfo.addressInfo;
} }
} }
window.customElements.define('start-minting', StartMinting); window.customElements.define('start-minting', StartMinting);

View File

@ -6,8 +6,6 @@ import { translate, translateUnsafeHTML } from 'lit-translate'
import '@polymer/paper-toast' import '@polymer/paper-toast'
import '@material/mwc-icon-button' import '@material/mwc-icon-button'
import './start-minting.js'
class WalletProfile extends connect(store)(LitElement) { class WalletProfile extends connect(store)(LitElement) {
static get properties() { static get properties() {
return { return {
@ -90,7 +88,6 @@ class WalletProfile extends connect(store)(LitElement) {
<p id="blocksMinted">${translate("walletprofile.blocksminted")} - ${this.accountInfo.addressInfo.blocksMinted + this.accountInfo.addressInfo.blocksMintedAdjustment}</p> <p id="blocksMinted">${translate("walletprofile.blocksminted")} - ${this.accountInfo.addressInfo.blocksMinted + this.accountInfo.addressInfo.blocksMintedAdjustment}</p>
<p id="address">${this.wallet.addresses[0].address}</p> <p id="address">${this.wallet.addresses[0].address}</p>
</div> </div>
<start-minting></start-minting>
</div> </div>
<paper-toast id="toast" horizontal-align="right" vertical-align="top" vertical-offset="64"></paper-toast> <paper-toast id="toast" horizontal-align="right" vertical-align="top" vertical-offset="64"></paper-toast>
` `

View File

@ -36,7 +36,7 @@ export default class PaymentTransaction extends TransactionBase {
} }
set amount(amount) { set amount(amount) {
this._amount = amount * store.getState().config.coin.decimals this._amount = Math.round(amount * store.getState().config.coin.decimals)
this._amountBytes = this.constructor.utils.int64ToBytes(this._amount) this._amountBytes = this.constructor.utils.int64ToBytes(this._amount)
} }