Created
April 3, 2022 22:33
-
-
Save mjohnsonengr/31da59ea75174e049ac1dd8545b31c21 to your computer and use it in GitHub Desktop.
Daedalus wallet koinly clean up script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function process() { | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const sheet = ss.getSheetByName("Clean Up Attempt for Script"); | |
const lastRow = sheet.getLastRow(); | |
const data = sheet.getDataRange().getValues(); | |
for (rowNum = lastRow; rowNum > 1; --rowNum) { | |
// stop before header row (rowNum == 1) | |
const row = data[rowNum-1]; | |
if (row[10].toString().length > 0) { | |
handleRowTokens(sheet, rowNum, row[0], row[9], row[10]); | |
} | |
} | |
} | |
function handleRowTokens(sheet, rowNum, date, txHash, tokens) { | |
// parse the tokens value | |
const rows = tokens.split(', ').map(tokenStr => { | |
let [amount, token] = tokenStr.split(' '); | |
token = token.substring(1, token.length-1); | |
// each new row has date and txHash as passed in | |
// Received Amount and Received Currency are per parsed values | |
return [date, "", "", amount, token, "", "", "", "", txHash]; | |
}); | |
if (rows.length < 1) { | |
console.error("Unexpected empty rows"); | |
return; | |
} | |
// insert one new row for each token parsed | |
sheet.insertRowsAfter(rowNum, rows.length); | |
sheet.getRange(rowNum+1, 1, rows.length, 10).setValues(rows); | |
Logger.log("handleRowTokens(" + rowNum + ", " + date + ", " + txHash + ", " + tokens + ")"); | |
Logger.log(rows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment