| 108 | |
| 109 | // Function to edit JSON file content |
| 110 | export function editJson(newData: Partial<Data>, filename: string = "data.json"): void { |
| 111 | if(!newData.pubkey) { |
| 112 | console.log("Pubkey is not prvided as an argument") |
| 113 | return |
| 114 | } |
| 115 | const wallets = readJson(filename); |
| 116 | const index = wallets.findIndex(wallet => wallet.pubkey === newData.pubkey); |
| 117 | if (index !== -1) { |
| 118 | wallets[index] = { ...wallets[index], ...newData }; |
| 119 | writeJson(wallets, filename); |
| 120 | } else { |
| 121 | console.error(`Pubkey ${newData.pubkey} does not exist.`); |
| 122 | } |
| 123 | } |
| 124 | |