From c0c27612fddf9a973e91f61886d7fba37ecbce44 Mon Sep 17 00:00:00 2001 From: Paul Puey Date: Tue, 15 Aug 2023 18:49:46 -0700 Subject: [PATCH] Add UI to get Bitwave accountId --- src/actions/TransactionExportActions.tsx | 3 +- .../scenes/TransactionsExportScene.tsx | 46 ++++++++++++++++++- src/locales/en_US.ts | 3 ++ src/locales/strings/enUS.json | 3 ++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/actions/TransactionExportActions.tsx b/src/actions/TransactionExportActions.tsx index 556af7a0da4..014f6b5f54b 100644 --- a/src/actions/TransactionExportActions.tsx +++ b/src/actions/TransactionExportActions.tsx @@ -393,6 +393,7 @@ export function exportTransactionsToCSVInner( export async function exportTransactionsToBitwave( wallet: EdgeCurrencyWallet, + accountId: string, edgeTransactions: EdgeTransaction[], currencyCode: string, multiplier: string, @@ -436,7 +437,7 @@ export async function exportTransactionsToBitwave( blockchainId: txid, memo: category, transactionType: isSend ? 'withdrawal' : 'deposit', - accountId: '', + accountId, contactId: '', categoryId: '', taxExempt: 'FALSE', diff --git a/src/components/scenes/TransactionsExportScene.tsx b/src/components/scenes/TransactionsExportScene.tsx index 08f929d1572..4846ab49a4c 100644 --- a/src/components/scenes/TransactionsExportScene.tsx +++ b/src/components/scenes/TransactionsExportScene.tsx @@ -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' @@ -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' @@ -51,6 +53,14 @@ interface State { isExportBitwave: boolean } +const EXPORT_TX_INFO_FILE = 'exportTxInfo.json' + +const asExportTxInfo = asObject({ + bitwaveAccountId: asString +}) + +type ExportTxInfo = ReturnType + class TransactionsExportSceneComponent extends React.PureComponent { constructor(props: Props) { super(props) @@ -173,6 +183,40 @@ class TransactionsExportSceneComponent extends React.PureComponent 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(bridge => ( + + ))) ?? '' + + 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 @@ -238,7 +282,7 @@ class TransactionsExportSceneComponent extends React.PureComponent } 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', diff --git a/src/locales/en_US.ts b/src/locales/en_US.ts index 9842668abdc..d1716c10cb2 100644 --- a/src/locales/en_US.ts +++ b/src/locales/en_US.ts @@ -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', diff --git a/src/locales/strings/enUS.json b/src/locales/strings/enUS.json index ac3148a5dfe..933d91cbba9 100644 --- a/src/locales/strings/enUS.json +++ b/src/locales/strings/enUS.json @@ -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",