Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Jekrimo committed Dec 5, 2024
1 parent 4c3edd5 commit 023b8e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/lib/components/messaging/ChatPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
return "Invalid message format"
}
const jsonPart = chat.last_message_preview.slice(jsonStartIndex)
console.log(JSON.parse(jsonPart))
let parsedMessage
try {
parsedMessage = JSON.parse(jsonPart)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"network": "Network",
"payment_declined": "Payment Declined",
"you_canceled_request": "You Canceled Request",
"paymentDeclined": "Payment Canceled",
"paymentCanceled": "Payment Canceled",
"youCanceledRequest": "You Canceled Payment Request",
"declinedPayment": "{user} Canceled Payment",
"recievedPayment": "{user} Sent You {amount}",
Expand Down
19 changes: 8 additions & 11 deletions src/lib/utils/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,33 +560,30 @@ export function getValidPaymentRequest(msg: string, msgId?: string): Transfer |
try {
let parsed = JSON.parse(json, (key, value) => {
if (key === "amount" && typeof value === "string") {
// Check if the value can be converted to BigInt
if (/^\d+$/.test(value)) {
return BigInt(value) // Convert to BigInt if it's an integer
return BigInt(value)
} else {
return value // Keep as string if it's a decimal
return value
}
}
return value
})

// Extract the details object for nested properties
const details = parsed.details || {}

transfer.asset = details.asset || {} // Ensure asset is retrieved from details
transfer.amount = details.amount || "0" // Use the nested amount
transfer.toAddress = details.toAddress || "" // Use the nested toAddress
transfer.amountPreview = details.amountPreview || "" // Use the nested amountPreview
transfer.asset = details.asset || {}
transfer.amount = details.amount || "0"
transfer.toAddress = details.toAddress || ""
transfer.amountPreview = details.amountPreview || ""
} catch (err) {
console.error("Parse Failed", err)
return undefined // Early return on parse failure
return undefined
}
} else {
console.error("Send message is not JSON:", json)
return undefined // Early return if message is not JSON
return undefined
}

// Validate transfer object properties safely
if (transfer.asset && transfer.asset.kind !== undefined && transfer.asset.kind !== AssetType.None && transfer.isValid()) {
return transfer
} else {
Expand Down
17 changes: 8 additions & 9 deletions src/routes/chat/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
function sanitizePaymentSent(message: string, sender: string, receiver: string): string {
const jsonStartIndex = message.indexOf("{")
const jsonEndIndex = message.lastIndexOf("}")
// console.log(message)
if (jsonStartIndex === -1 || jsonEndIndex === -1 || jsonStartIndex > jsonEndIndex) {
return "Invalid message format"
Expand All @@ -175,7 +174,7 @@
try {
parsedMessage = JSON.parse(jsonPart)
} catch (error) {
// console.error("Error parsing JSON:", error, message)
console.error("Error parsing JSON:", error, message)
return "Invalid message format"
}
Expand Down Expand Up @@ -406,7 +405,6 @@
let chat = get(Store.state.activeChat)
let txt = formattedMessage.split("\n")
console.log(txt)
let walletSuccess = await getValidPaymentRequest(line, message.id)?.execute()
if (walletSuccess) {
Expand All @@ -416,13 +414,12 @@
const alreadyRejected = payments.some(payment => payment.messageId === message.id)
if (!alreadyRejected) {
return [...payments, { messageId: message.id, senderId: message.details.origin, rejectedPayment: true }]
return [...payments, { messageId: message.id, senderId: message.details.origin, rejectedPayment: false }]
} else {
console.error(`MessageId ${message.id} is already in the rejected payments list`)
return payments
}
})
console.log(txt)
ConversationStore.addPendingMessages(chat.id, res.message, txt)
})
}
Expand Down Expand Up @@ -467,7 +464,7 @@
let wasAdded = false
Store.state.paymentTracker.update(payments => {
const alreadyRejected = payments.some(payment => payment.messageId === messageId)
console.log(message, payments)
if (!alreadyRejected) {
wasAdded = true
return [...payments, { messageId, senderId: message.details.origin, rejectedPayment: false }]
Expand Down Expand Up @@ -952,17 +949,19 @@
<Icon icon={Shape.XMark}></Icon>
</Button>
{:else}
<Text hook="text-chat-message" class="send_coin" markdown={$_("payments.sentRequest")}></Text>
<!-- <Text hook="text-chat-message" class="send_coin" markdown={$_("payments.sentRequest")}></Text>
<Button
hook="text-chat-message"
text={$_("payments.canceledRequest")}
appearance={Appearance.Error}
on:click={async () => sendPaymentMessage(message, line, PaymentRequestsEnum.Reject)}>
<Icon icon={Shape.XMark}></Icon>
</Button>
</Button> -->
{/if}
{:else if line.startsWith(PaymentRequestsEnum.Send) && $rejectedPayments.find(payments => payments.messageId === message.id && payments.rejectedPayment)}
<Button hook="text-chat-message" disabled text={$_("payments.Success")} appearance={Appearance.Success} />
{:else}
<Button hook="text-chat-message" disabled text={$_("payments.paymentDeclined")} appearance={Appearance.Error} />
<Button hook="text-chat-message" disabled text={$_("payments.paymentCanceled")} appearance={Appearance.Error} />
{/if}
{:else if !line.includes(tempCDN)}
<Text hook="text-chat-message" markdown={line} appearance={group.details.remote ? Appearance.Default : Appearance.Alt} />
Expand Down

0 comments on commit 023b8e5

Please sign in to comment.