Skip to content

Commit

Permalink
Fix bitwave csv export
Browse files Browse the repository at this point in the history
- Move category to metadata1
- Add notes to memo and metadata2
- change id to hash of txid and various other tx data to make it unique across all wallets
  • Loading branch information
paullinator authored and swansontec committed Sep 4, 2023
1 parent daba33f commit c1659fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"redux-thunk": "^2.3.0",
"rn-id-blurview": "^1.2.1",
"rn-qr-generator": "^1.3.1",
"sha.js": "^2.4.11",
"sprintf-js": "^1.1.1",
"url": "^0.11.0",
"url-parse": "^1.5.2",
Expand Down Expand Up @@ -226,6 +227,7 @@
"@types/react-native-safari-view": "^2.0.5",
"@types/react-native-vector-icons": "^6.4.13",
"@types/react-test-renderer": "^18.0.0",
"@types/sha.js": "^2.4.1",
"@types/sprintf-js": "^1.1.2",
"@types/url-parse": "^1.4.8",
"@types/uuid": "^7.0.0",
Expand Down
22 changes: 17 additions & 5 deletions src/actions/TransactionExportActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { abs, add, div, gt, lt, mul } from 'biggystring'
import csvStringify from 'csv-stringify/lib/browser/sync'
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'
import shajs from 'sha.js'

import { getExchangeDenomination } from '../selectors/DenominationSelectors'
import { ThunkAction } from '../types/reduxTypes'
Expand Down Expand Up @@ -407,13 +408,14 @@ export async function exportTransactionsToBitwave(
}

function edgeTxToCsv(edgeTx: EdgeTransaction) {
const { date, isSend, metadata, nativeAmount, networkFee, parentNetworkFee, txid } = edgeTx
const { date, isSend, metadata, nativeAmount, networkFee, ourReceiveAddresses, parentNetworkFee, spendTargets, txid } = edgeTx
const amount: string = abs(div(nativeAmount, multiplier, DECIMAL_PRECISION))
const time = makeBitwaveDateTime(date)
let fee: string = ''
let feeTicker: string = ''
const { name = '', category = '', notes = '' } = metadata ?? {}

let toAddress = ''
if (isSend) {
if (parentNetworkFee != null) {
feeTicker = parentCode
Expand All @@ -422,10 +424,19 @@ export async function exportTransactionsToBitwave(
feeTicker = currencyCode
fee = div(networkFee, multiplier, DECIMAL_PRECISION)
}
if (spendTargets && spendTargets.length > 0) {
// We can only choose 1 `toAddress` so pick the first spendTarget
toAddress = spendTargets[0].publicAddress
}
} else {
// We can only choose 1 `toAddress` so pick the first receive address
toAddress = ourReceiveAddresses != null ? ourReceiveAddresses[0] : ''
}

const id = shajs('sha256').update(`${txid}_${nativeAmount}_${networkFee}_${toAddress}`).digest('hex').slice(0, 16)

items.push({
id: txid,
id,
remoteContactId: '',
amount,
amountTicker: currencyCode,
Expand All @@ -435,7 +446,7 @@ export async function exportTransactionsToBitwave(
feeTicker,
time,
blockchainId: txid,
memo: category,
memo: notes,
transactionType: isSend ? 'withdrawal' : 'deposit',
accountId,
contactId: '',
Expand All @@ -444,9 +455,10 @@ export async function exportTransactionsToBitwave(
tradeId: '',
description: name,
fromAddress: '',
toAddress: '',
toAddress,
groupId: '',
'metadata:myCustomMetadata1': notes
'metadata:myCustomMetadata1': category,
'metadata:myCustomMetadata2': notes
})
}

Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4033,6 +4033,13 @@
"@types/mime" "^1"
"@types/node" "*"

"@types/sha.js@^2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/sha.js/-/sha.js-2.4.1.tgz#d7c71b0035360cf120f0a8e8ed4a2eab07a0d51c"
integrity sha512-QHWKOJ4dkWB0OCfCoOFUZkhvpqUllcPs2WIhYFk7ugAprv3ts0z4nSuHtc0jlWBYLdPwfNRpVpv9pIpFSbYBYQ==
dependencies:
"@types/node" "*"

"@types/sockjs@^0.3.33":
version "0.3.33"
resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.33.tgz#570d3a0b99ac995360e3136fd6045113b1bd236f"
Expand Down Expand Up @@ -14857,7 +14864,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==

[email protected], sha.js@^2.3.6, sha.js@^2.4.0, sha.js@^2.4.8:
[email protected], sha.js@^2.3.6, sha.js@^2.4.0, sha.js@^2.4.11, sha.js@^2.4.8:
version "2.4.11"
resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.11.tgz#37a5cf0b81ecbc6943de109ba2960d1b26584ae7"
integrity sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==
Expand Down

0 comments on commit c1659fa

Please sign in to comment.