Skip to content

Commit

Permalink
Generate random paymentId
Browse files Browse the repository at this point in the history
  • Loading branch information
n9lsjr committed Mar 11, 2024
1 parent 0ea2ff3 commit c24206c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/backend/electron.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Store = require("electron-store");
const { autoUpdater } = require("electron-updater");
const fs = require("fs");
const { createSwarm, destroySwarm, sendMessage } = require("./hyper/index.cjs");
const { error } = require("console");


try {
Expand Down Expand Up @@ -631,6 +632,12 @@ ipcMain.handle('balance-subwallet', async (e) => {

ipcMain.handle('prepare-transaction', async (e, address, amount, paymentID, sendAll) => {
console.log(address, amount, paymentID, sendAll);
if (paymentID !== undefined) {
if (!WB.validatePaymentID(paymentID)) {
errorMessage('The paymentId is not correct')
return
}
}
const result = await walletBackend.sendTransactionAdvanced(
[[address, parseInt(parseFloat(amount).toFixed(5) * 100000)]],
3,
Expand Down Expand Up @@ -661,7 +668,10 @@ ipcMain.handle('prepare-transaction', async (e, address, amount, paymentID, send

ipcMain.handle('send-transaction', async (e, hash) => {
const result = await walletBackend.sendPreparedTransaction(hash)
if (!result.success) errorMessage('Error: Could not send transaction')
if (!result.success) {
errorMessage('Error: Could not send transaction')
return
}
successMessage('Transaction sent!')
mainWindow.webContents.send("outgoing-tx")
return result.success;
Expand All @@ -676,8 +686,8 @@ ipcMain.handle('validate-address', async (e, address) => {
return await WB.validateAddress(address, true)
})

ipcMain.handle('generate-paymentId', async (e, paymentId) => {
return WB.validatePaymentID(paymentId);
ipcMain.handle('generate-paymentId', async (e) => {
return (await crypto.generateKeys()).public_key
})


Expand Down
4 changes: 1 addition & 3 deletions src/backend/preload.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ contextBridge.exposeInMainWorld("api", {
return await ipcRenderer.invoke('import-contacts')
},



prepareTransaction: async (address, amount, paymentID, sendAll) => {
return await ipcRenderer.invoke('prepare-transaction', address, amount, paymentID, sendAll)
},
Expand All @@ -115,7 +113,7 @@ contextBridge.exposeInMainWorld("api", {
return await ipcRenderer.invoke('validate-address', address)
},
generatePaymentId: async () => {
return await ipcRenderer.invoke('validate-paymentId')
return await ipcRenderer.invoke('generate-paymentId')
},
validatePaymentId: async (paymentId) => {
return await ipcRenderer.invoke('validate-paymentId', paymentId)
Expand Down
5 changes: 4 additions & 1 deletion src/routes/wallet/send/PrepareTransaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
if ($wallet.preparedTransaction) {
address = '';
amount = '';
paymentId = '';
}
};
const generatePaymentId = () => {};
const generatePaymentId = async () => {
paymentId = await window.api.generatePaymentId();
};
//Validate and paste address
const pasteAddress = async () => {
Expand Down

0 comments on commit c24206c

Please sign in to comment.