forked from Qortal/qortal-ui
fixed a couple bugs
This commit is contained in:
parent
0b613beed6
commit
78942e6bd9
@ -55,10 +55,10 @@ const parentEpml = new Epml({ type: 'WINDOW', source: window.parent })
|
||||
|
||||
export const queue = new RequestQueue();
|
||||
|
||||
export const chatLimit = 40
|
||||
export const chatLimitHalf = 20
|
||||
export const chatLimit = 20
|
||||
export const chatLimitHalf = 10
|
||||
|
||||
export const totalMsgCount = 120
|
||||
export const totalMsgCount = 60
|
||||
class ChatPage extends LitElement {
|
||||
static get properties() {
|
||||
return {
|
||||
@ -2810,6 +2810,14 @@ class ChatPage extends LitElement {
|
||||
}
|
||||
|
||||
async getOldMessage(scrollElement) {
|
||||
if(!scrollElement || !scrollElement.messageObj || !scrollElement.messageObj.timestamp){
|
||||
this.messagesRendered = {
|
||||
messages: [],
|
||||
type: 'old',
|
||||
el: scrollElement
|
||||
}
|
||||
return
|
||||
}
|
||||
if (this.isReceipient) {
|
||||
const getInitialMessages = await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
@ -2910,6 +2918,13 @@ class ChatPage extends LitElement {
|
||||
}
|
||||
}
|
||||
async getAfterMessages(scrollElement) {
|
||||
if(!scrollElement || !scrollElement.messageObj || !scrollElement.messageObj.timestamp){
|
||||
this.messagesRendered = {
|
||||
messages: [],
|
||||
type: 'new',
|
||||
}
|
||||
return
|
||||
}
|
||||
const timestamp = scrollElement.messageObj.timestamp
|
||||
|
||||
if (this.isReceipient) {
|
||||
|
@ -260,7 +260,6 @@ export const chatStyles = css`
|
||||
.message-parent {
|
||||
padding: 3px;
|
||||
background: rgba(245, 245, 245, 0);
|
||||
transition: all 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
.message-parent:hover {
|
||||
@ -368,7 +367,6 @@ export const chatStyles = css`
|
||||
background:#fff;
|
||||
color: #000;
|
||||
text-align: center;
|
||||
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
|
||||
font-size: 12px;
|
||||
z-index: 5;
|
||||
white-space: nowrap;
|
||||
@ -414,7 +412,6 @@ export const chatStyles = css`
|
||||
width: 150px;
|
||||
height: 32px;
|
||||
padding: 3px 8px;
|
||||
box-shadow: rgba(77, 77, 82, 0.2) 0px 7px 29px 0px;
|
||||
}
|
||||
|
||||
.block-user:hover {
|
||||
|
@ -593,6 +593,7 @@ class ChatScroller extends LitElement {
|
||||
async updated(changedProperties) {
|
||||
if (changedProperties && changedProperties.has('messages')) {
|
||||
if (this.messages.type === 'initial') {
|
||||
|
||||
this.addNewMessages(this.messages.messages, 'initial')
|
||||
|
||||
|
||||
@ -1118,6 +1119,12 @@ class MessageTemplate extends LitElement {
|
||||
if (changedProperties.has('messageObj')) {
|
||||
return true
|
||||
}
|
||||
if(changedProperties.has('showBlockAddressIcon')){
|
||||
return true
|
||||
}
|
||||
if(changedProperties.has('openDialogBlockUser')){
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1130,7 +1137,6 @@ class MessageTemplate extends LitElement {
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const hidemsg = this.hideMessages
|
||||
let message = ""
|
||||
let messageVersion2 = ""
|
||||
|
@ -99,211 +99,136 @@ export class TipUser extends LitElement {
|
||||
}
|
||||
|
||||
async sendQort() {
|
||||
const amount = this.shadowRoot.getElementById("amountInput").value
|
||||
let recipient = this.userName
|
||||
this.sendMoneyLoading = true
|
||||
this.btnDisable = true
|
||||
|
||||
if (parseFloat(amount) + parseFloat(0.011) > parseFloat(this.walletBalance)) {
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
let snack1string = get("chatpage.cchange51")
|
||||
parentEpml.request('showSnackBar', `${snack1string}`)
|
||||
return false
|
||||
}
|
||||
|
||||
if (parseFloat(amount) <= 0) {
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
let snack2string = get("chatpage.cchange52")
|
||||
parentEpml.request('showSnackBar', `${snack2string}`)
|
||||
return false
|
||||
}
|
||||
|
||||
if (recipient.length === 0) {
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
let snack3string = get("chatpage.cchange53")
|
||||
parentEpml.request('showSnackBar', `${snack3string}`)
|
||||
return false
|
||||
}
|
||||
|
||||
const validateName = async (receiverName) => {
|
||||
let myRes
|
||||
let myNameRes = await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
url: `/names/${receiverName}`,
|
||||
})
|
||||
|
||||
if (myNameRes.error === 401) {
|
||||
myRes = false
|
||||
} else {
|
||||
myRes = myNameRes
|
||||
const amount = this.shadowRoot.getElementById("amountInput").value;
|
||||
const recipient = this.userName;
|
||||
|
||||
this.sendMoneyLoading = true;
|
||||
this.btnDisable = true;
|
||||
|
||||
// Helper function to reset loading and button state
|
||||
const resetState = () => {
|
||||
this.sendMoneyLoading = false;
|
||||
this.btnDisable = false;
|
||||
}
|
||||
return myRes
|
||||
}
|
||||
|
||||
const validateAddress = async (receiverAddress) => {
|
||||
let myAddress = await window.parent.validateAddress(receiverAddress)
|
||||
return myAddress
|
||||
}
|
||||
|
||||
const validateReceiver = async (recipient) => {
|
||||
let lastRef = await this.getLastRef()
|
||||
let theFee = await this.getSendQortFee()
|
||||
let isAddress
|
||||
|
||||
try {
|
||||
isAddress = await validateAddress(recipient)
|
||||
} catch (err) {
|
||||
isAddress = false
|
||||
|
||||
if (parseFloat(amount) + parseFloat(0.011) > parseFloat(this.walletBalance)) {
|
||||
resetState();
|
||||
const snack1string = get("chatpage.cchange51");
|
||||
parentEpml.request('showSnackBar', `${snack1string}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isAddress) {
|
||||
let myTransaction = await makeTransactionRequest(recipient, lastRef, theFee)
|
||||
getTxnRequestResponse(myTransaction)
|
||||
} else {
|
||||
let myNameRes = await validateName(recipient)
|
||||
if (myNameRes !== false) {
|
||||
let myNameAddress = myNameRes.owner
|
||||
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef, theFee)
|
||||
getTxnRequestResponse(myTransaction)
|
||||
} else {
|
||||
let myNameRes = await validateName(recipient)
|
||||
if (myNameRes !== false) {
|
||||
let myNameAddress = myNameRes.owner
|
||||
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef)
|
||||
getTxnRequestResponse(myTransaction)
|
||||
} else {
|
||||
console.error(this.renderReceiverText())
|
||||
this.errorMessage = this.renderReceiverText()
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
}
|
||||
}
|
||||
|
||||
if (parseFloat(amount) <= 0) {
|
||||
resetState();
|
||||
const snack2string = get("chatpage.cchange52");
|
||||
parentEpml.request('showSnackBar', `${snack2string}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (recipient.length === 0) {
|
||||
resetState();
|
||||
const snack3string = get("chatpage.cchange53");
|
||||
parentEpml.request('showSnackBar', `${snack3string}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const validateName = async (receiverName) => {
|
||||
const myNameRes = await parentEpml.request('apiCall', {
|
||||
type: 'api',
|
||||
url: `/names/${receiverName}`
|
||||
});
|
||||
return myNameRes.error === 401 ? false : myNameRes;
|
||||
};
|
||||
|
||||
const validateAddress = async (receiverAddress) => {
|
||||
return await window.parent.validateAddress(receiverAddress);
|
||||
};
|
||||
|
||||
const getName = async (recipient) => {
|
||||
try {
|
||||
const getNames = await parentEpml.request("apiCall", {
|
||||
type: "api",
|
||||
url: `/names/address/${recipient}`,
|
||||
url: `/names/address/${recipient}`
|
||||
});
|
||||
|
||||
if (getNames?.length > 0) {
|
||||
return getNames[0].name
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
return getNames?.length > 0 ? getNames[0].name : '';
|
||||
} catch (error) {
|
||||
return ""
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const makeTransactionRequest = async (receiver, lastRef) => {
|
||||
let myReceiver = receiver
|
||||
let mylastRef = lastRef
|
||||
let dialogamount = get("transactions.amount")
|
||||
let dialogAddress = get("login.address")
|
||||
let dialogName = get("login.name")
|
||||
let dialogto = get("transactions.to")
|
||||
let recipientName = await getName(myReceiver)
|
||||
let myTxnrequest = await parentEpml.request('transaction', {
|
||||
const dialogAmount = get("transactions.amount");
|
||||
const dialogAddress = get("login.address");
|
||||
const dialogName = get("login.name");
|
||||
const dialogTo = get("transactions.to");
|
||||
const recipientName = await getName(receiver);
|
||||
|
||||
return await parentEpml.request('transaction', {
|
||||
type: 2,
|
||||
nonce: this.myAddress.nonce,
|
||||
params: {
|
||||
recipient: myReceiver,
|
||||
recipient: receiver,
|
||||
recipientName: recipientName,
|
||||
amount: amount,
|
||||
lastReference: mylastRef,
|
||||
fee: 0.001,
|
||||
dialogamount: dialogamount,
|
||||
dialogto: dialogto,
|
||||
lastReference: lastRef,
|
||||
fee: this.qortPaymentFee,
|
||||
dialogAmount,
|
||||
dialogTo,
|
||||
dialogAddress,
|
||||
dialogName
|
||||
},
|
||||
})
|
||||
return myTxnrequest
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getTxnRequestResponse = (txnResponse) => {
|
||||
if (txnResponse.success === false && txnResponse.message) {
|
||||
this.errorMessage = txnResponse.message
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
throw new Error(txnResponse)
|
||||
this.errorMessage = txnResponse.message;
|
||||
resetState();
|
||||
throw new Error(txnResponse);
|
||||
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
||||
this.shadowRoot.getElementById('amountInput').value = ''
|
||||
this.errorMessage = ''
|
||||
this.successMessage = this.renderSuccessText()
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
this.shadowRoot.getElementById('amountInput').value = '';
|
||||
this.errorMessage = '';
|
||||
this.successMessage = this.renderSuccessText();
|
||||
resetState();
|
||||
setTimeout(() => {
|
||||
this.setOpenTipUser(false)
|
||||
this.successMessage = ""
|
||||
}, 3000)
|
||||
this.setOpenTipUser(false);
|
||||
this.successMessage = "";
|
||||
}, 3000);
|
||||
} else {
|
||||
this.errorMessage = txnResponse.data.message
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
throw new Error(txnResponse)
|
||||
this.errorMessage = txnResponse.data.message;
|
||||
resetState();
|
||||
throw new Error(txnResponse);
|
||||
}
|
||||
}
|
||||
validateReceiver(recipient)
|
||||
}
|
||||
|
||||
const makeTransactionRequest = async (receiver, lastRef, theFee) => {
|
||||
let myReceiver = receiver
|
||||
let mylastRef = lastRef
|
||||
let myFee = theFee
|
||||
let dialogamount = get("transactions.amount")
|
||||
let dialogAddress = get("login.address")
|
||||
let dialogName = get("login.name")
|
||||
let dialogto = get("transactions.to")
|
||||
let recipientName = await getName(myReceiver)
|
||||
let myTxnrequest = await parentEpml.request('transaction', {
|
||||
type: 2,
|
||||
nonce: this.myAddress.nonce,
|
||||
params: {
|
||||
recipient: myReceiver,
|
||||
recipientName: recipientName,
|
||||
amount: amount,
|
||||
lastReference: mylastRef,
|
||||
fee: myFee,
|
||||
dialogamount: dialogamount,
|
||||
dialogto: dialogto,
|
||||
dialogAddress,
|
||||
dialogName
|
||||
},
|
||||
})
|
||||
return myTxnrequest
|
||||
}
|
||||
|
||||
const getTxnRequestResponse = (txnResponse) => {
|
||||
if (txnResponse.success === false && txnResponse.message) {
|
||||
this.errorMessage = txnResponse.message
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
throw new Error(txnResponse)
|
||||
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
||||
this.shadowRoot.getElementById('amountInput').value = ''
|
||||
this.errorMessage = ''
|
||||
this.successMessage = this.renderSuccessText()
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
setTimeout(() => {
|
||||
this.setOpenTipUser(false)
|
||||
this.successMessage = ""
|
||||
}, 3000)
|
||||
} else {
|
||||
this.errorMessage = txnResponse.data.message
|
||||
this.sendMoneyLoading = false
|
||||
this.btnDisable = false
|
||||
throw new Error(txnResponse)
|
||||
}
|
||||
}
|
||||
validateReceiver(recipient)
|
||||
};
|
||||
|
||||
const validateReceiver = async (recipient) => {
|
||||
let lastRef = await this.getLastRef();
|
||||
let isAddress;
|
||||
|
||||
try {
|
||||
isAddress = await validateAddress(recipient);
|
||||
} catch (err) {
|
||||
isAddress = false;
|
||||
}
|
||||
|
||||
if (isAddress) {
|
||||
const myTransaction = await makeTransactionRequest(recipient, lastRef);
|
||||
getTxnRequestResponse(myTransaction);
|
||||
} else {
|
||||
const myNameRes = await validateName(recipient);
|
||||
if (myNameRes !== false) {
|
||||
const myTransaction = await makeTransactionRequest(myNameRes.owner, lastRef);
|
||||
getTxnRequestResponse(myTransaction);
|
||||
} else {
|
||||
this.errorMessage = this.renderReceiverText();
|
||||
resetState();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await validateReceiver(recipient);
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return html`
|
||||
|
Loading…
x
Reference in New Issue
Block a user