mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-12 02:05:51 +00:00
Update to QDN
This commit is contained in:
parent
053fc89d39
commit
81f6a11d89
76
qortal-ui-core/src/apiKeyUtils.js
Normal file
76
qortal-ui-core/src/apiKeyUtils.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import * as api from 'qortal-ui-crypto'
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
export const checkApiKey = async (nodeConfig) => {
|
||||||
|
|
||||||
|
let selectedNode = nodeConfig.knownNodes[nodeConfig.node];
|
||||||
|
if (selectedNode.enableManagement === false) {
|
||||||
|
console.log("Skipping API key check because enableManagement is false");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let apiKey = selectedNode.apiKey;
|
||||||
|
|
||||||
|
// Attempt to generate an API key
|
||||||
|
const generateUrl = "/admin/apikey/generate";
|
||||||
|
let generateRes = await api.request(generateUrl, {
|
||||||
|
method: "POST"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (generateRes != null && generateRes.error == null && generateRes.length >= 8) {
|
||||||
|
console.log("Generated API key");
|
||||||
|
apiKey = generateRes;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Unable to generate API key");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now test the API key
|
||||||
|
let testResult = await testApiKey(apiKey);
|
||||||
|
if (testResult === true) {
|
||||||
|
console.log("API key test passed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("API key test failed");
|
||||||
|
|
||||||
|
let apiKeyValid = false;
|
||||||
|
|
||||||
|
while (apiKeyValid === false) {
|
||||||
|
|
||||||
|
let apiKeyPrompt = prompt("Please enter the API key for this node.\n\nIt can be found in a file called 'apikey.txt' in the directory where the core is installed.\n\nAlternatively, click Cancel to use the core with reduced functionality.", "");
|
||||||
|
if (apiKeyPrompt === null) {
|
||||||
|
// Cancel was pushed - so give up
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let testResult = await testApiKey(apiKeyPrompt);
|
||||||
|
if (testResult === true) {
|
||||||
|
console.log("API key prompt test passed");
|
||||||
|
apiKeyValid = true;
|
||||||
|
apiKey = apiKeyPrompt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("API key prompt test failed. Re-prompting...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store API key
|
||||||
|
selectedNode.apiKey = apiKey;
|
||||||
|
nodeConfig.knownNodes[nodeConfig.node] = selectedNode;
|
||||||
|
localStorage.setItem('myQortalNodes', JSON.stringify(nodeConfig.knownNodes));
|
||||||
|
}
|
||||||
|
|
||||||
|
export const testApiKey = async (apiKey) => {
|
||||||
|
const testUrl = "/admin/apikey/test?apiKey=" + apiKey;
|
||||||
|
let testRes = await api.request(testUrl, {
|
||||||
|
method: "GET"
|
||||||
|
});
|
||||||
|
if (testRes === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
@ -97,7 +97,7 @@ class AppInfo extends connect(store)(LitElement) {
|
|||||||
return html`
|
return html`
|
||||||
<div id="profileInMenu">
|
<div id="profileInMenu">
|
||||||
<span class="info">Block Height: ${this.blockInfo.height ? this.blockInfo.height : ''} <span class=${this.cssStatus}>${this._renderStatus()}</span></span>
|
<span class="info">Block Height: ${this.blockInfo.height ? this.blockInfo.height : ''} <span class=${this.cssStatus}>${this._renderStatus()}</span></span>
|
||||||
<span class="info">UI Version: v${this.nodeConfig.version ? this.nodeConfig.version : ''} </span>
|
<span class="info">UI Version: ${this.nodeConfig.version ? this.nodeConfig.version : ''} </span>
|
||||||
<span class="info">Core Version: ${this.nodeInfo.buildVersion ? this.nodeInfo.buildVersion : ''} </span>
|
<span class="info">Core Version: ${this.nodeInfo.buildVersion ? this.nodeInfo.buildVersion : ''} </span>
|
||||||
<a id="pageLink"></a>
|
<a id="pageLink"></a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,6 +10,7 @@ import FileSaver from 'file-saver'
|
|||||||
|
|
||||||
import { doLogin, doLogout, doSelectAddress } from '../../redux/app/app-actions.js'
|
import { doLogin, doLogout, doSelectAddress } from '../../redux/app/app-actions.js'
|
||||||
import { doStoreWallet } from '../../redux/user/user-actions.js'
|
import { doStoreWallet } from '../../redux/user/user-actions.js'
|
||||||
|
import { checkApiKey } from '../../apiKeyUtils.js'
|
||||||
|
|
||||||
import snackbar from '../../functional-components/snackbar.js'
|
import snackbar from '../../functional-components/snackbar.js'
|
||||||
|
|
||||||
@ -48,7 +49,8 @@ class CreateAccountSection extends connect(store)(LitElement) {
|
|||||||
_wallet: { type: Object },
|
_wallet: { type: Object },
|
||||||
_pass: { type: String },
|
_pass: { type: String },
|
||||||
_name: { type: String },
|
_name: { type: String },
|
||||||
isDownloadedBackup: { type: Boolean }
|
isDownloadedBackup: { type: Boolean },
|
||||||
|
nodeConfig: { type: Object }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +183,7 @@ class CreateAccountSection extends connect(store)(LitElement) {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
store.dispatch(doLogin(this._wallet))
|
store.dispatch(doLogin(this._wallet))
|
||||||
store.dispatch(doSelectAddress(this._wallet.addresses[0]))
|
store.dispatch(doSelectAddress(this._wallet.addresses[0]))
|
||||||
|
checkApiKey(this.nodeConfig);
|
||||||
this.cleanup()
|
this.cleanup()
|
||||||
return ripple.fade()
|
return ripple.fade()
|
||||||
})
|
})
|
||||||
@ -191,6 +194,7 @@ class CreateAccountSection extends connect(store)(LitElement) {
|
|||||||
} else {
|
} else {
|
||||||
store.dispatch(doLogin(this._wallet))
|
store.dispatch(doLogin(this._wallet))
|
||||||
store.dispatch(doSelectAddress(this._wallet.addresses[0]))
|
store.dispatch(doSelectAddress(this._wallet.addresses[0]))
|
||||||
|
checkApiKey()
|
||||||
this.cleanup()
|
this.cleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,6 +494,7 @@ class CreateAccountSection extends connect(store)(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stateChanged(state) {
|
stateChanged(state) {
|
||||||
|
this.nodeConfig = state.app.nodeConfig
|
||||||
// this.loggedIn = state.app.loggedIn
|
// this.loggedIn = state.app.loggedIn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { LitElement, html, css } from 'lit-element'
|
import { LitElement, html, css } from 'lit-element'
|
||||||
import { connect } from 'pwa-helpers'
|
import { connect } from 'pwa-helpers'
|
||||||
import { store } from '../../store.js'
|
import { store } from '../../store.js'
|
||||||
|
import { checkApiKey } from '../../apiKeyUtils.js'
|
||||||
|
|
||||||
import '@material/mwc-button'
|
import '@material/mwc-button'
|
||||||
import '@material/mwc-checkbox'
|
import '@material/mwc-checkbox'
|
||||||
@ -45,7 +46,8 @@ class LoginSection extends connect(store)(LitElement) {
|
|||||||
hasStoredWallets: { type: Boolean },
|
hasStoredWallets: { type: Boolean },
|
||||||
saveInBrowser: { type: Boolean },
|
saveInBrowser: { type: Boolean },
|
||||||
backedUpWalletJSON: { type: Object },
|
backedUpWalletJSON: { type: Object },
|
||||||
backedUpSeedLoading: { type: Boolean }
|
backedUpSeedLoading: { type: Boolean },
|
||||||
|
nodeConfig: { type: Object }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +282,7 @@ class LoginSection extends connect(store)(LitElement) {
|
|||||||
<div page="seed" id="seedPage">
|
<div page="seed" id="seedPage">
|
||||||
<div>
|
<div>
|
||||||
<div style="display:flex;">
|
<div style="display:flex;">
|
||||||
<mwc-textfield style="width:100%;" icon="clear_all" label="Qora address seed" id="v1SeedInput" type="password"></mwc-textfield>
|
<mwc-textfield style="width:100%;" icon="clear_all" label="Qortal address seed" id="v1SeedInput" type="password"></mwc-textfield>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -375,6 +377,7 @@ class LoginSection extends connect(store)(LitElement) {
|
|||||||
this.loggedIn = state.app.loggedIn
|
this.loggedIn = state.app.loggedIn
|
||||||
this.wallets = state.user.storedWallets
|
this.wallets = state.user.storedWallets
|
||||||
this.hasStoredWallets = this.wallets.length > 0
|
this.hasStoredWallets = this.wallets.length > 0
|
||||||
|
this.nodeConfig = state.app.nodeConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
keyupEnter(e, action) {
|
keyupEnter(e, action) {
|
||||||
@ -535,6 +538,7 @@ class LoginSection extends connect(store)(LitElement) {
|
|||||||
})).catch(err => console.error(err))
|
})).catch(err => console.error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
checkApiKey(this.nodeConfig)
|
||||||
this.cleanup()
|
this.cleanup()
|
||||||
return this.loadingRipple.fade()
|
return this.loadingRipple.fade()
|
||||||
})
|
})
|
||||||
|
@ -11,6 +11,7 @@ import framePasteMenu from '../functional-components/frame-paste-menu.js'
|
|||||||
const createTransaction = api.createTransaction
|
const createTransaction = api.createTransaction
|
||||||
const processTransaction = api.processTransaction
|
const processTransaction = api.processTransaction
|
||||||
const signChatTransaction = api.signChatTransaction
|
const signChatTransaction = api.signChatTransaction
|
||||||
|
const signArbitraryTransaction = api.signArbitraryTransaction
|
||||||
const tradeBotCreateRequest = api.tradeBotCreateRequest
|
const tradeBotCreateRequest = api.tradeBotCreateRequest
|
||||||
const tradeBotRespondRequest = api.tradeBotRespondRequest
|
const tradeBotRespondRequest = api.tradeBotRespondRequest
|
||||||
const signTradeBotTxn = api.signTradeBotTxn
|
const signTradeBotTxn = api.signTradeBotTxn
|
||||||
@ -206,6 +207,21 @@ export const routes = {
|
|||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sign_arbitrary: async (req) => {
|
||||||
|
let response
|
||||||
|
try {
|
||||||
|
const signedArbitraryBytes = await signArbitraryTransaction(req.data.arbitraryBytesBase58, req.data.arbitraryBytesForSigningBase58, req.data.arbitraryNonce, store.getState().app.wallet._addresses[req.data.nonce].keyPair)
|
||||||
|
|
||||||
|
const res = await processTransaction(signedArbitraryBytes)
|
||||||
|
response = res
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
console.error(e.message)
|
||||||
|
response = false
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
|
||||||
showNotification: async (req) => {
|
showNotification: async (req) => {
|
||||||
doNewMessage(req.data)
|
doNewMessage(req.data)
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user