mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-03-14 03:32:33 +00:00
Merge remote-tracking branch 'JustinWesleyFerrari/feature/qapps-modals' into q-apps
# Conflicts: # qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js # qortal-ui-plugins/plugins/utils/publish-image.js
This commit is contained in:
commit
0215a03988
@ -525,7 +525,19 @@
|
||||
"bchange13": "Error occurred when trying to block this registered name. Please try again!",
|
||||
"bchange14": "Error occurred when trying to unblock this registered name. Please try again!",
|
||||
"bchange15": "Can't delete data from followed names. Please unfollow first.",
|
||||
"bchange16": "Error occurred when trying to delete this resource. Please try again!"
|
||||
"bchange16": "Error occurred when trying to delete this resource. Please try again!",
|
||||
"bchange17": "User declined to share account details",
|
||||
"bchange18": "has requested authentication. Would you like to authenticate?",
|
||||
"bchange19": "Do you give this application permission to publish to QDN?",
|
||||
"bchange20": "Do you give this application permission to get your wallet balance?",
|
||||
"bchange21": "Fetch Wallet Failed. Please try again!",
|
||||
"bchange22": "Do you give this application permission to send a chat message?",
|
||||
"bchange23": "Message Sent!",
|
||||
"bchange24": "This shares your QORT address and allows your account to interact with the",
|
||||
"bchange25": "No sensitive data is shared.",
|
||||
"bchange26": "Always authenticate automatically",
|
||||
"bchange27": "Reject",
|
||||
"bchange28": "Accept"
|
||||
},
|
||||
"datapage": {
|
||||
"dchange1": "Data Management",
|
||||
|
@ -14,14 +14,15 @@ import './login-section.js'
|
||||
import '../qort-theme-toggle.js'
|
||||
|
||||
import settings from '../../functional-components/settings-page.js'
|
||||
import { addAutoLoadImageChat, removeAutoLoadImageChat, addChatLastSeen } from '../../redux/app/app-actions.js'
|
||||
import { addAutoLoadImageChat, removeAutoLoadImageChat, addChatLastSeen, allowQAPPAutoAuth, removeQAPPAutoAuth } from '../../redux/app/app-actions.js'
|
||||
|
||||
window.reduxStore = store
|
||||
window.reduxAction = {
|
||||
addAutoLoadImageChat: addAutoLoadImageChat,
|
||||
removeAutoLoadImageChat: removeAutoLoadImageChat,
|
||||
addChatLastSeen: addChatLastSeen
|
||||
|
||||
addChatLastSeen: addChatLastSeen,
|
||||
allowQAPPAutoAuth: allowQAPPAutoAuth,
|
||||
removeQAPPAutoAuth: removeQAPPAutoAuth
|
||||
}
|
||||
|
||||
const animationDuration = 0.7 // Seconds
|
||||
|
@ -22,6 +22,7 @@ import framePasteMenu from '../functional-components/frame-paste-menu.js';
|
||||
|
||||
const createTransaction = api.createTransaction;
|
||||
const processTransaction = api.processTransaction;
|
||||
const processTransactionVersion2 = api.processTransactionVersion2;
|
||||
const signChatTransaction = api.signChatTransaction;
|
||||
const signArbitraryTransaction = api.signArbitraryTransaction;
|
||||
const tradeBotCreateRequest = api.tradeBotCreateRequest;
|
||||
@ -144,8 +145,16 @@ export const routes = {
|
||||
if (!req.disableModal && !req.data.disableModal) {
|
||||
await requestTransactionDialog.requestTransaction(tx);
|
||||
}
|
||||
|
||||
const res = await processTransaction(tx.signedBytes);
|
||||
|
||||
let res
|
||||
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(tx.signedBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(tx.signedBytes);
|
||||
}
|
||||
|
||||
let extraData = {}
|
||||
if(req.data.type === 38 && tx && tx._rewardShareKeyPair && tx._rewardShareKeyPair.secretKey){
|
||||
extraData.rewardSharePrivateKey = Base58.encode(tx._rewardShareKeyPair.secretKey)
|
||||
@ -191,7 +200,16 @@ export const routes = {
|
||||
_keyPair,
|
||||
req.data.params
|
||||
);
|
||||
const res = await processTransaction(tx.signedBytes);
|
||||
let res
|
||||
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(tx.signedBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(tx.signedBytes);
|
||||
}
|
||||
|
||||
|
||||
response = {
|
||||
success: true,
|
||||
data: res,
|
||||
@ -242,8 +260,16 @@ export const routes = {
|
||||
req.data.chatNonce,
|
||||
store.getState().app.wallet._addresses[req.data.nonce].keyPair
|
||||
);
|
||||
|
||||
let res
|
||||
|
||||
const res = await processTransaction(signedChatBytes);
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(signedChatBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(signedChatBytes);
|
||||
}
|
||||
|
||||
response = res;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@ -262,8 +288,15 @@ export const routes = {
|
||||
req.data.arbitraryNonce,
|
||||
store.getState().app.wallet._addresses[req.data.nonce].keyPair
|
||||
);
|
||||
let res
|
||||
|
||||
const res = await processTransaction(signedArbitraryBytes);
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(signedArbitraryBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(signedArbitraryBytes);
|
||||
}
|
||||
|
||||
response = res;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@ -293,8 +326,14 @@ export const routes = {
|
||||
unsignedTxn,
|
||||
store.getState().app.selectedAddress.keyPair
|
||||
);
|
||||
let res
|
||||
|
||||
const res = await processTransaction(signedTxnBytes);
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(signedTxnBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(signedTxnBytes);
|
||||
}
|
||||
response = res;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@ -327,8 +366,15 @@ export const routes = {
|
||||
unsignedTxn,
|
||||
store.getState().app.selectedAddress.keyPair
|
||||
);
|
||||
|
||||
let res
|
||||
|
||||
const res = await processTransaction(signedTxnBytes);
|
||||
if(req.data.apiVersion && req.data.apiVersion === 2){
|
||||
res = await processTransactionVersion2(signedTxnBytes)
|
||||
}
|
||||
if(!req.data.apiVersion){
|
||||
res = await processTransaction(signedTxnBytes);
|
||||
}
|
||||
|
||||
response = res;
|
||||
} catch (e) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Core App Actions here...
|
||||
import { UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, CHAT_HEADS, ACCOUNT_INFO, COPY_MENU_SWITCH, PASTE_MENU_SWITCH, FRAME_PASTE_MENU_SWITCH, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN } from '../app-action-types.js'
|
||||
import { UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, CHAT_HEADS, ACCOUNT_INFO, COPY_MENU_SWITCH, PASTE_MENU_SWITCH, FRAME_PASTE_MENU_SWITCH, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN } from '../app-action-types.js'
|
||||
|
||||
export const doUpdateBlockInfo = (blockObj) => {
|
||||
return (dispatch, getState) => {
|
||||
@ -120,6 +120,20 @@ export const removeAutoLoadImageChat = (payload) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const allowQAPPAutoAuth = (payload) => {
|
||||
return {
|
||||
type: ALLOW_QAPP_AUTO_AUTH,
|
||||
payload
|
||||
}
|
||||
}
|
||||
|
||||
export const removeQAPPAutoAuth = (payload) => {
|
||||
return {
|
||||
type: REMOVE_QAPP_AUTO_AUTH,
|
||||
payload
|
||||
}
|
||||
}
|
||||
|
||||
export const setChatLastSeen = (payload) => {
|
||||
return {
|
||||
type: SET_CHAT_LAST_SEEN,
|
||||
|
@ -22,5 +22,7 @@ export const PASTE_MENU_SWITCH = 'PASTE_MENU_SWITCH'
|
||||
export const FRAME_PASTE_MENU_SWITCH = 'FRAME_PASTE_MENU_SWITCH'
|
||||
export const ADD_AUTO_LOAD_IMAGES_CHAT = 'ADD_AUTO_LOAD_IMAGES_CHAT'
|
||||
export const REMOVE_AUTO_LOAD_IMAGES_CHAT = 'REMOVE_AUTO_LOAD_IMAGES_CHAT'
|
||||
export const ALLOW_QAPP_AUTO_AUTH = 'ALLOW_QAPP_AUTO_AUTH'
|
||||
export const REMOVE_QAPP_AUTO_AUTH = 'REMOVE_QAPP_AUTO_AUTH'
|
||||
export const SET_CHAT_LAST_SEEN = 'SET_CHAT_LAST_SEEN'
|
||||
export const ADD_CHAT_LAST_SEEN = 'ADD_CHAT_LAST_SEEN'
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Loading state, login state, isNavDrawOpen state etc. None of this needs to be saved to localstorage.
|
||||
import { loadStateFromLocalStorage, saveStateToLocalStorage } from '../../localStorageHelpers.js'
|
||||
import { LOG_IN, LOG_OUT, NETWORK_CONNECTION_STATUS, INIT_WORKERS, ADD_PLUGIN_URL, ADD_PLUGIN, ADD_NEW_PLUGIN_URL, NAVIGATE, SELECT_ADDRESS, ACCOUNT_INFO, CHAT_HEADS, UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, LOAD_NODE_CONFIG, SET_NODE, ADD_NODE, PAGE_URL, COPY_MENU_SWITCH, PASTE_MENU_SWITCH, FRAME_PASTE_MENU_SWITCH, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN } from './app-action-types.js'
|
||||
import { LOG_IN, LOG_OUT, NETWORK_CONNECTION_STATUS, INIT_WORKERS, ADD_PLUGIN_URL, ADD_PLUGIN, ADD_NEW_PLUGIN_URL, NAVIGATE, SELECT_ADDRESS, ACCOUNT_INFO, CHAT_HEADS, UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, LOAD_NODE_CONFIG, SET_NODE, ADD_NODE, PAGE_URL, COPY_MENU_SWITCH, PASTE_MENU_SWITCH, FRAME_PASTE_MENU_SWITCH, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN } from './app-action-types.js'
|
||||
import { initWorkersReducer } from './reducers/init-workers.js'
|
||||
import { loginReducer } from './reducers/login-reducer.js'
|
||||
import { setNode, addNode } from './reducers/manage-node.js'
|
||||
@ -50,6 +50,7 @@ const INITIAL_STATE = {
|
||||
elementId: ''
|
||||
},
|
||||
autoLoadImageChats: loadStateFromLocalStorage('autoLoadImageChats') || [],
|
||||
qAPPAutoAuth: loadStateFromLocalStorage('qAPPAutoAuth') || false,
|
||||
chatLastSeen: []
|
||||
}
|
||||
|
||||
@ -175,6 +176,23 @@ export default (state = INITIAL_STATE, action) => {
|
||||
autoLoadImageChats: updatedState
|
||||
}
|
||||
}
|
||||
|
||||
case ALLOW_QAPP_AUTO_AUTH: {
|
||||
saveStateToLocalStorage("qAPPAutoAuth", true)
|
||||
return {
|
||||
...state,
|
||||
qAPPAutoAuth: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
case REMOVE_QAPP_AUTO_AUTH: {
|
||||
saveStateToLocalStorage("qAPPAutoAuth", false)
|
||||
return {
|
||||
...state,
|
||||
qAPPAutoAuth: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
case SET_CHAT_LAST_SEEN: {
|
||||
return {
|
||||
...state,
|
||||
|
@ -1,5 +1,5 @@
|
||||
export { request } from './fetch-request.js'
|
||||
export { transactionTypes as transactions } from './transactions/transactions.js'
|
||||
export { processTransaction, createTransaction, computeChatNonce, signChatTransaction, signArbitraryTransaction } from './createTransaction.js'
|
||||
export { processTransaction, processTransactionVersion2, createTransaction, computeChatNonce, signChatTransaction, signArbitraryTransaction } from './createTransaction.js'
|
||||
export { tradeBotCreateRequest, tradeBotRespondRequest, signTradeBotTxn, deleteTradeOffer, sendBtc, sendLtc, sendDoge, sendDgb, sendRvn, sendArrr } from './tradeRequest.js'
|
||||
export { cancelAllOffers } from './transactions/trade-portal/tradeoffer/cancelAllOffers.js'
|
||||
|
@ -36,3 +36,9 @@ export const processTransaction = bytes => request('/transactions/process', {
|
||||
method: 'POST',
|
||||
body: Base58.encode(bytes)
|
||||
})
|
||||
|
||||
export const processTransactionVersion2 = bytes => request('/transactions/process?apiVersion=2', {
|
||||
method: 'POST',
|
||||
body: Base58.encode(bytes)
|
||||
})
|
||||
|
||||
|
91
qortal-ui-crypto/api/transactions/DeployAtTransaction.js
Normal file
91
qortal-ui-crypto/api/transactions/DeployAtTransaction.js
Normal file
@ -0,0 +1,91 @@
|
||||
'use strict'
|
||||
import TransactionBase from './TransactionBase.js'
|
||||
import { store } from '../../api.js'
|
||||
|
||||
export default class DeployAtTransaction extends TransactionBase {
|
||||
constructor() {
|
||||
super()
|
||||
this.type = 16
|
||||
}
|
||||
|
||||
render(html) {
|
||||
return html`
|
||||
${this._groupdialog5}
|
||||
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
||||
<div>${this._atDeployDialog1}: <span style="color: #000;">${this._rName}</span></div>
|
||||
<br>
|
||||
<div>${this.atDeployDialog2}: <span style="color: #000;">${this._rDescription}</span></div>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
${this._groupdialog6}
|
||||
`
|
||||
}
|
||||
|
||||
set atDeployDialog1(atDeployDialog1) {
|
||||
this._atDeployDialog1 = atDeployDialog1
|
||||
}
|
||||
set atDeployDialog2(atDeployDialog2) {
|
||||
this._atDeployDialog2 = atDeployDialog2
|
||||
}
|
||||
|
||||
set fee(fee) {
|
||||
this._fee = fee
|
||||
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||
}
|
||||
set rAmount(rAmount) {
|
||||
this._rAmount = Math.round(rAmount * store.getState().config.coin.decimals)
|
||||
this._rAmountBytes = this.constructor.utils.int64ToBytes(this._rAmount)
|
||||
}
|
||||
|
||||
set rName(rName) {
|
||||
this._rName = rName
|
||||
this._rNameBytes = this.constructor.utils.stringtoUTF8Array(this._rName.toLocaleLowerCase())
|
||||
this._rNameLength = this.constructor.utils.int32ToBytes(this._rNameBytes.length)
|
||||
}
|
||||
|
||||
set rDescription(rDescription) {
|
||||
this._rDescription = rDescription
|
||||
this._rDescriptionBytes = this.constructor.utils.stringtoUTF8Array(this._rDescription.toLocaleLowerCase())
|
||||
this._rDescriptionLength = this.constructor.utils.int32ToBytes(this._rDescriptionBytes.length)
|
||||
}
|
||||
set atType(atType) {
|
||||
this._atType = atType
|
||||
this._atTypeBytes = this.constructor.utils.stringtoUTF8Array(this._atType)
|
||||
this._atTypeLength = this.constructor.utils.int32ToBytes(this._atTypeBytes.length)
|
||||
}
|
||||
set rTags(rTags) {
|
||||
this._rTags = rTags
|
||||
this._rTagsBytes = this.constructor.utils.stringtoUTF8Array(this._rTags.toLocaleLowerCase())
|
||||
this._rTagsLength = this.constructor.utils.int32ToBytes(this._rTagsBytes.length)
|
||||
}
|
||||
set rCreationBytes(rCreationBytes) {
|
||||
const decode = this.constructor.Base58.decode(rCreationBytes)
|
||||
this._rCreationBytes = this.constructor.utils.stringtoUTF8Array(decode)
|
||||
this._rCreationBytesLength = this.constructor.utils.int32ToBytes(this._rCreationBytes.length)
|
||||
}
|
||||
set rAssetId(rAssetId) {
|
||||
this._rAssetId = this.constructor.utils.int64ToBytes(rAssetId)
|
||||
}
|
||||
|
||||
|
||||
get params() {
|
||||
const params = super.params
|
||||
params.push(
|
||||
this._rNameLength,
|
||||
this._rNameBytes,
|
||||
this._rDescriptionLength,
|
||||
this._rDescriptionBytes,
|
||||
this._atTypeLength,
|
||||
this._atTypeBytes,
|
||||
this._rTagsLength,
|
||||
this._rTagsBytes,
|
||||
this._rCreationBytesLength,
|
||||
this._rCreationBytes,
|
||||
this._rAmountBytes,
|
||||
this._rAssetId,
|
||||
this._feeBytes
|
||||
)
|
||||
return params
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import LeaveGroupTransaction from './groups/LeaveGroupTransaction.js'
|
||||
import RewardShareTransaction from './reward-share/RewardShareTransaction.js'
|
||||
import RemoveRewardShareTransaction from './reward-share/RemoveRewardShareTransaction.js'
|
||||
import TransferPrivsTransaction from './TransferPrivsTransaction.js'
|
||||
import DeployAtTransaction from './DeployAtTransaction.js'
|
||||
|
||||
export const transactionTypes = {
|
||||
2: PaymentTransaction,
|
||||
@ -30,6 +31,7 @@ export const transactionTypes = {
|
||||
5: SellNameTransacion,
|
||||
6: CancelSellNameTransacion,
|
||||
7: BuyNameTransacion,
|
||||
16: DeployAtTransaction,
|
||||
17: MessageTransaction,
|
||||
18: ChatTransaction,
|
||||
181: GroupChatTransaction,
|
||||
|
@ -0,0 +1,26 @@
|
||||
// GET_USER_ACCOUNT action
|
||||
export const GET_USER_ACCOUNT = 'GET_USER_ACCOUNT';
|
||||
|
||||
// LINK_TO_QDN_RESOURCE action
|
||||
export const LINK_TO_QDN_RESOURCE = 'LINK_TO_QDN_RESOURCE';
|
||||
|
||||
// QDN_RESOURCE_DISPLAYED action
|
||||
export const QDN_RESOURCE_DISPLAYED = 'QDN_RESOURCE_DISPLAYED';
|
||||
|
||||
// PUBLISH_QDN_RESOURCE action
|
||||
export const PUBLISH_QDN_RESOURCE = 'PUBLISH_QDN_RESOURCE';
|
||||
|
||||
// SEND_CHAT_MESSAGE action
|
||||
export const SEND_CHAT_MESSAGE = 'SEND_CHAT_MESSAGE';
|
||||
|
||||
// JOIN_GROUP action
|
||||
export const JOIN_GROUP = 'JOIN_GROUP';
|
||||
|
||||
// DEPLOY_AT action
|
||||
export const DEPLOY_AT = 'DEPLOY_AT';
|
||||
|
||||
// GET_WALLET_BALANCE action
|
||||
export const GET_WALLET_BALANCE = 'GET_WALLET_BALANCE';
|
||||
|
||||
// SEND_COIN action
|
||||
export const SEND_COIN = 'SEND_COIN';
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,82 @@
|
||||
import { Sha256 } from 'asmcrypto.js'
|
||||
|
||||
|
||||
function sbrk(size, heap){
|
||||
let brk = 512 * 1024 // stack top
|
||||
let old = brk
|
||||
brk += size
|
||||
|
||||
if (brk > heap.length)
|
||||
throw new Error('heap exhausted')
|
||||
|
||||
return old
|
||||
}
|
||||
|
||||
|
||||
|
||||
self.addEventListener('message', async e => {
|
||||
const response = await computePow(e.data.chatBytes, e.data.path, e.data.difficulty)
|
||||
postMessage(response)
|
||||
|
||||
})
|
||||
|
||||
|
||||
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 })
|
||||
const heap = new Uint8Array(memory.buffer)
|
||||
|
||||
|
||||
|
||||
const computePow = async (chatBytes, path, difficulty) => {
|
||||
|
||||
let response = null
|
||||
|
||||
await new Promise((resolve, reject)=> {
|
||||
|
||||
const _chatBytesArray = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; });
|
||||
const chatBytesArray = new Uint8Array(_chatBytesArray);
|
||||
const chatBytesHash = new Sha256().process(chatBytesArray).finish().result;
|
||||
const hashPtr = sbrk(32, heap);
|
||||
const hashAry = new Uint8Array(memory.buffer, hashPtr, 32);
|
||||
hashAry.set(chatBytesHash);
|
||||
|
||||
|
||||
const workBufferLength = 8 * 1024 * 1024;
|
||||
const workBufferPtr = sbrk(workBufferLength, heap);
|
||||
|
||||
|
||||
|
||||
const importObject = {
|
||||
env: {
|
||||
memory: memory
|
||||
},
|
||||
};
|
||||
|
||||
function loadWebAssembly(filename, imports) {
|
||||
// Fetch the file and compile it
|
||||
return fetch(filename)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.compile(buffer))
|
||||
.then(module => {
|
||||
|
||||
// Create the instance.
|
||||
return new WebAssembly.Instance(module, importObject);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
loadWebAssembly(path)
|
||||
.then(wasmModule => {
|
||||
response = {
|
||||
nonce : wasmModule.exports.compute2(hashPtr, workBufferPtr, workBufferLength, difficulty),
|
||||
chatBytesArray
|
||||
}
|
||||
|
||||
resolve()
|
||||
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
|
||||
return response
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
import { Sha256 } from 'asmcrypto.js'
|
||||
|
||||
|
||||
|
||||
function sbrk(size, heap){
|
||||
let brk = 512 * 1024 // stack top
|
||||
let old = brk
|
||||
brk += size
|
||||
|
||||
if (brk > heap.length)
|
||||
throw new Error('heap exhausted')
|
||||
|
||||
return old
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
self.addEventListener('message', async e => {
|
||||
const response = await computePow(e.data.convertedBytes, e.data.path)
|
||||
postMessage(response)
|
||||
|
||||
})
|
||||
|
||||
|
||||
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 })
|
||||
const heap = new Uint8Array(memory.buffer)
|
||||
|
||||
|
||||
|
||||
const computePow = async (convertedBytes, path) => {
|
||||
|
||||
|
||||
let response = null
|
||||
|
||||
await new Promise((resolve, reject)=> {
|
||||
|
||||
const _convertedBytesArray = Object.keys(convertedBytes).map(
|
||||
function (key) {
|
||||
return convertedBytes[key]
|
||||
}
|
||||
)
|
||||
const convertedBytesArray = new Uint8Array(_convertedBytesArray)
|
||||
const convertedBytesHash = new Sha256()
|
||||
.process(convertedBytesArray)
|
||||
.finish().result
|
||||
const hashPtr = sbrk(32, heap)
|
||||
const hashAry = new Uint8Array(
|
||||
memory.buffer,
|
||||
hashPtr,
|
||||
32
|
||||
)
|
||||
|
||||
hashAry.set(convertedBytesHash)
|
||||
const difficulty = 14
|
||||
const workBufferLength = 8 * 1024 * 1024
|
||||
const workBufferPtr = sbrk(
|
||||
workBufferLength,
|
||||
heap
|
||||
)
|
||||
|
||||
const importObject = {
|
||||
env: {
|
||||
memory: memory
|
||||
},
|
||||
};
|
||||
|
||||
function loadWebAssembly(filename, imports) {
|
||||
return fetch(filename)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.compile(buffer))
|
||||
.then(module => {
|
||||
return new WebAssembly.Instance(module, importObject);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
loadWebAssembly(path)
|
||||
.then(wasmModule => {
|
||||
response = {
|
||||
nonce : wasmModule.exports.compute2(hashPtr, workBufferPtr, workBufferLength, difficulty),
|
||||
|
||||
}
|
||||
resolve()
|
||||
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
|
||||
return response
|
||||
}
|
52
qortal-ui-plugins/plugins/utils/loader.js
Normal file
52
qortal-ui-plugins/plugins/utils/loader.js
Normal file
@ -0,0 +1,52 @@
|
||||
export class Loader {
|
||||
constructor() {
|
||||
this.loader = document.createElement("div");
|
||||
this.loader.className = "loader";
|
||||
this.loader.innerHTML = `
|
||||
<div class="loader-spinner"></div>
|
||||
`;
|
||||
this.styles = document.createElement("style");
|
||||
this.styles.innerHTML = `
|
||||
.loader {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000001
|
||||
}
|
||||
|
||||
.loader-spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #3498db;
|
||||
border-radius: 50%;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
show() {
|
||||
document.head.appendChild(this.styles);
|
||||
document.body.appendChild(this.loader);
|
||||
}
|
||||
|
||||
hide() {
|
||||
if (this.loader.parentNode) {
|
||||
this.loader.parentNode.removeChild(this.loader);
|
||||
}
|
||||
if (this.styles.parentNode) {
|
||||
this.styles.parentNode.removeChild(this.styles);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,8 @@ export const publishData = async ({
|
||||
selectedAddress,
|
||||
worker,
|
||||
isBase64,
|
||||
metaData
|
||||
metaData,
|
||||
apiVersion
|
||||
}) => {
|
||||
const validateName = async (receiverName) => {
|
||||
let nameRes = await parentEpml.request("apiCall", {
|
||||
@ -44,7 +45,7 @@ export const publishData = async ({
|
||||
transactionBytesBase58
|
||||
)
|
||||
if (convertedBytesBase58.error) {
|
||||
return
|
||||
throw new Error('Error when signing');
|
||||
}
|
||||
|
||||
const convertedBytes =
|
||||
@ -71,10 +72,11 @@ export const publishData = async ({
|
||||
arbitraryBytesBase58: transactionBytesBase58,
|
||||
arbitraryBytesForSigningBase58: convertedBytesBase58,
|
||||
arbitraryNonce: nonce,
|
||||
apiVersion: apiVersion ? apiVersion : null
|
||||
})
|
||||
let myResponse = { error: "" }
|
||||
if (response === false) {
|
||||
return
|
||||
throw new Error('Error when signing');
|
||||
} else {
|
||||
myResponse = response
|
||||
}
|
||||
@ -85,21 +87,22 @@ export const publishData = async ({
|
||||
const validate = async () => {
|
||||
let validNameRes = await validateName(registeredName)
|
||||
if (validNameRes.error) {
|
||||
return
|
||||
throw new Error('Name not found');
|
||||
}
|
||||
let transactionBytes = await uploadData(registeredName, path, file)
|
||||
if (transactionBytes.error) {
|
||||
return
|
||||
throw new Error('Error when uploading');
|
||||
} else if (
|
||||
transactionBytes.includes("Error 500 Internal Server Error")
|
||||
) {
|
||||
return
|
||||
throw new Error('Error when uploading');
|
||||
}
|
||||
|
||||
let signAndProcessRes = await signAndProcess(transactionBytes)
|
||||
if (signAndProcessRes.error) {
|
||||
return
|
||||
throw new Error('Error when signing');
|
||||
}
|
||||
return signAndProcessRes
|
||||
}
|
||||
|
||||
const uploadData = async (registeredName, path, file) => {
|
||||
@ -147,7 +150,8 @@ export const publishData = async ({
|
||||
}
|
||||
}
|
||||
try {
|
||||
await validate()
|
||||
const validateRes = await validate()
|
||||
return validateRes
|
||||
} catch (error) {
|
||||
throw new Error(error.message)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user