Skip to content

Commit

Permalink
Add UI to get Bitwave accountId
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Aug 28, 2023
1 parent 6dad4c2 commit c0c2761
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/actions/TransactionExportActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export function exportTransactionsToCSVInner(

export async function exportTransactionsToBitwave(
wallet: EdgeCurrencyWallet,
accountId: string,
edgeTransactions: EdgeTransaction[],
currencyCode: string,
multiplier: string,
Expand Down Expand Up @@ -436,7 +437,7 @@ export async function exportTransactionsToBitwave(
blockchainId: txid,
memo: category,
transactionType: isSend ? 'withdrawal' : 'deposit',
accountId: '',
accountId,
contactId: '',
categoryId: '',
taxExempt: 'FALSE',
Expand Down
46 changes: 45 additions & 1 deletion src/components/scenes/TransactionsExportScene.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { asObject, asString } from 'cleaners'
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'
import * as React from 'react'
import { Platform, ScrollView } from 'react-native'
Expand All @@ -14,6 +15,7 @@ import { EdgeSceneProps } from '../../types/routerTypes'
import { getWalletName } from '../../util/CurrencyWalletHelpers'
import { SceneWrapper } from '../common/SceneWrapper'
import { DateModal } from '../modals/DateModal'
import { TextInputModal } from '../modals/TextInputModal'
import { Airship, showError } from '../services/AirshipInstance'
import { ThemeProps, withTheme } from '../services/ThemeContext'
import { SettingsHeaderRow } from '../settings/SettingsHeaderRow'
Expand Down Expand Up @@ -51,6 +53,14 @@ interface State {
isExportBitwave: boolean
}

const EXPORT_TX_INFO_FILE = 'exportTxInfo.json'

const asExportTxInfo = asObject({
bitwaveAccountId: asString
})

type ExportTxInfo = ReturnType<typeof asExportTxInfo>

class TransactionsExportSceneComponent extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props)
Expand Down Expand Up @@ -173,6 +183,40 @@ class TransactionsExportSceneComponent extends React.PureComponent<Props, State>
const { exchangeMultiplier, multiplier, parentMultiplier, route } = this.props
const { sourceWallet, currencyCode } = route.params
const { isExportBitwave, isExportQbo, isExportCsv, startDate, endDate } = this.state

let accountId = ''
if (isExportBitwave) {
let fileAccountId = ''
try {
const result = await sourceWallet.disklet.getText(EXPORT_TX_INFO_FILE)
fileAccountId = asExportTxInfo(JSON.parse(result)).bitwaveAccountId
} catch (e) {
console.log(`Could not read ${EXPORT_TX_INFO_FILE} ${String(e)}. Failure is ok`)
}

accountId =
(await Airship.show<string | undefined>(bridge => (
<TextInputModal
autoFocus
autoCorrect={false}
bridge={bridge}
initialValue={fileAccountId}
inputLabel={lstrings.export_transaction_bitwave_accountid_modal_input_label}
message={lstrings.export_transaction_bitwave_accountid_modal_message}
returnKeyType="next"
submitLabel={lstrings.string_next_capitalized}
title={lstrings.export_transaction_bitwave_accountid_modal_title}
/>
))) ?? ''

if (accountId !== fileAccountId) {
const exportTxInfo: ExportTxInfo = {
bitwaveAccountId: accountId
}
await sourceWallet.disklet.setText(EXPORT_TX_INFO_FILE, JSON.stringify(exportTxInfo))
}
}

if (startDate.getTime() > endDate.getTime()) {
showError(lstrings.export_transaction_error)
return
Expand Down Expand Up @@ -238,7 +282,7 @@ class TransactionsExportSceneComponent extends React.PureComponent<Props, State>
}

if (isExportBitwave) {
const bitwaveFile = await exportTransactionsToBitwave(sourceWallet, txs, currencyCode, exchangeMultiplier, parentMultiplier)
const bitwaveFile = await exportTransactionsToBitwave(sourceWallet, accountId, txs, currencyCode, exchangeMultiplier, parentMultiplier)
files.push({
contents: bitwaveFile,
mimeType: 'text/comma-separated-values',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,9 @@ const strings = {
export_transaction_quickbooks_qbo: 'Quickbooks QBO',
export_transaction_csv: 'CSV',
export_transaction_bitwave_csv: 'Bitwave CSV',
export_transaction_bitwave_accountid_modal_title: 'Bitwave Account ID',
export_transaction_bitwave_accountid_modal_message: 'Please enter the Bitwave account ID for this wallet',
export_transaction_bitwave_accountid_modal_input_label: 'Account ID',
string_export: 'Export',
string_status: 'Status',
string_fee: 'Fee',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@
"export_transaction_quickbooks_qbo": "Quickbooks QBO",
"export_transaction_csv": "CSV",
"export_transaction_bitwave_csv": "Bitwave CSV",
"export_transaction_bitwave_accountid_modal_title": "Bitwave Account ID",
"export_transaction_bitwave_accountid_modal_message": "Please enter the Bitwave account ID for this wallet",
"export_transaction_bitwave_accountid_modal_input_label": "Account ID",
"string_export": "Export",
"string_status": "Status",
"string_fee": "Fee",
Expand Down

0 comments on commit c0c2761

Please sign in to comment.