Skip to content

Commit 3300399

Browse files
committed
Merge remote-tracking branch 'benma/nopanic'
2 parents eb4af2f + 52da637 commit 3300399

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

backend/coins/btc/account.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ func (account *Account) Transactions() (accounts.OrderedTransactions, error) {
666666
if account.fatalError.Load() {
667667
return nil, errp.New("can't call Transactions() after a fatal error")
668668
}
669-
txs, err := account.transactions.Transactions(
669+
return account.transactions.Transactions(
670670
func(scriptHashHex blockchain.ScriptHashHex) bool {
671671
for _, subacc := range account.subaccounts {
672672
if subacc.changeAddresses.LookupByScriptHashHex(scriptHashHex) != nil {
@@ -675,11 +675,6 @@ func (account *Account) Transactions() (accounts.OrderedTransactions, error) {
675675
}
676676
return false
677677
})
678-
if err != nil {
679-
// TODO
680-
panic(err)
681-
}
682-
return txs, nil
683678
}
684679

685680
// GetUnusedReceiveAddresses returns a number of unused addresses. Returns nil if the account is not initialized.

backend/coins/btc/handlers/handlers.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,19 @@ func (handlers *Handlers) getTxInfoJSON(txInfo *accounts.TransactionData, detail
220220
}
221221

222222
func (handlers *Handlers) getAccountTransactions(_ *http.Request) (interface{}, error) {
223-
result := []Transaction{}
223+
var result struct {
224+
Success bool `json:"success"`
225+
Transactions []Transaction `json:"list"`
226+
}
224227
txs, err := handlers.account.Transactions()
225228
if err != nil {
226-
return nil, err
229+
return result, nil
227230
}
231+
result.Transactions = []Transaction{}
228232
for _, txInfo := range txs {
229-
result = append(result, handlers.getTxInfoJSON(txInfo, false))
233+
result.Transactions = append(result.Transactions, handlers.getTxInfoJSON(txInfo, false))
230234
}
235+
result.Success = true
231236
return result, nil
232237
}
233238

frontends/web/src/api/account.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export interface ITransaction {
176176
weight: number;
177177
}
178178

179+
export type TTransactions = { success: false } | { success: true; list: ITransaction[]; };
180+
179181
export interface INoteTx {
180182
internalTxID: string;
181183
note: string;
@@ -188,7 +190,7 @@ export const postNotesTx = (code: AccountCode, {
188190
return apiPost(`account/${code}/notes/tx`, { internalTxID, note });
189191
};
190192

191-
export const getTransactionList = (code: AccountCode): Promise<ITransaction[]> => {
193+
export const getTransactionList = (code: AccountCode): Promise<TTransactions> => {
192194
return apiGet(`account/${code}/transactions`);
193195
};
194196

frontends/web/src/components/transactions/transactions.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { useTranslation } from 'react-i18next';
19-
import { ITransaction } from '../../api/account';
19+
import { TTransactions } from '../../api/account';
2020
import A from '../../components/anchor/anchor';
2121
import { runningInAndroid } from '../../utils/env';
2222
import { Transaction } from './transaction';
@@ -25,7 +25,7 @@ import style from './transactions.module.css';
2525
type TProps = {
2626
accountCode: string;
2727
explorerURL: string;
28-
transactions?: ITransaction[];
28+
transactions?: TTransactions;
2929
handleExport: () => void;
3030
};
3131

@@ -62,8 +62,8 @@ export const Transactions = ({
6262
<div className={style.currency}>{t('transaction.details.amount')}</div>
6363
<div className={style.action}>&nbsp;</div>
6464
</div>
65-
{ (transactions && transactions.length > 0)
66-
? transactions.map((props, index) => (
65+
{ (transactions && transactions.success && transactions.list.length > 0)
66+
? transactions.list.map((props, index) => (
6767
<Transaction
6868
accountCode={accountCode}
6969
key={props.internalID}
@@ -72,7 +72,11 @@ export const Transactions = ({
7272
{...props} />
7373
)) : (
7474
<div className={`flex flex-row flex-center ${style.empty}`}>
75-
<p>{t('transactions.placeholder')}</p>
75+
{ transactions && !transactions.success ? (
76+
<p>{t('transactions.errorLoadTransactions')}</p>
77+
) : (
78+
<p>{t('transactions.placeholder')}</p>
79+
) }
7680
</div>
7781
) }
7882
</div>

frontends/web/src/locales/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@
14071407
"weight": "Weight"
14081408
},
14091409
"transactions": {
1410+
"errorLoadTransactions": "There was an error loading the transactions",
14101411
"placeholder": "No transactions yet."
14111412
},
14121413
"unknownError": "An unknown error occurred: {{errorMessage}}",

frontends/web/src/routes/account/account.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function Account({
5757
const [balance, setBalance] = useState<accountApi.IBalance>();
5858
const [status, setStatus] = useState<accountApi.IStatus>();
5959
const [syncedAddressesCount, setSyncedAddressesCount] = useState<number>();
60-
const [transactions, setTransactions] = useState<accountApi.ITransaction[]>();
60+
const [transactions, setTransactions] = useState<accountApi.TTransactions>();
6161
const [usesProxy, setUsesProxy] = useState<boolean>();
6262
const [stateCode, setStateCode] = useState<string>();
6363
const supportedExchanges = useLoad<SupportedExchanges>(getExchangeBuySupported(code), [code]);
@@ -191,7 +191,8 @@ export function Account({
191191
&& !balance.hasAvailable
192192
&& !balance.hasIncoming
193193
&& transactions
194-
&& transactions.length === 0;
194+
&& transactions.success
195+
&& transactions.list.length === 0;
195196

196197
const showBuyButton = exchangeBuySupported && isAccountEmpty;
197198

@@ -266,7 +267,7 @@ export function Account({
266267
account={account}
267268
unit={balance?.available.unit}
268269
hasIncomingBalance={balance && balance.hasIncoming}
269-
hasTransactions={transactions !== undefined && transactions.length > 0}
270+
hasTransactions={transactions !== undefined && transactions.success && transactions.list.length > 0}
270271
hasNoBalance={balance && balance.available.amount === '0'} />
271272
</div>
272273
);

frontends/web/src/routes/buy/pocket.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ export const Pocket = ({ code }: TProps) => {
161161

162162
const handleRequestXpub = () => {
163163
getTransactionList(code).then(txs => {
164-
if (txs.length > 0) {
164+
if (!txs.success) {
165+
alertUser(t('transactions.errorLoadTransactions'));
166+
return;
167+
}
168+
if (txs.list.length > 0) {
165169
confirmation(t('buy.pocket.previousTransactions'), result => {
166170
if (result) {
167171
sendXpub();

0 commit comments

Comments
 (0)