From 83903285b98e13c69316d79cea31fa0f3dc3ab8d Mon Sep 17 00:00:00 2001 From: annakaz Date: Tue, 17 Dec 2019 09:58:42 -0800 Subject: [PATCH 1/9] WIP --- packages/mobile/src/apollo/types.ts | 6 ++-- .../src/transactions/TransactionFeed.tsx | 29 +++++++++++-------- packages/mobile/src/transactions/reducer.ts | 20 ++++++++++++- packages/utils/src/phoneNumbers.ts | 4 ++- packages/walletkit/src/contract-utils.ts | 5 +++- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/packages/mobile/src/apollo/types.ts b/packages/mobile/src/apollo/types.ts index d3d57b23ad0..eebb990730b 100644 --- a/packages/mobile/src/apollo/types.ts +++ b/packages/mobile/src/apollo/types.ts @@ -1,5 +1,5 @@ import { Query } from 'react-apollo' -import { TransactionTypes } from 'src/transactions/reducer' +import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/reducer' export interface UserTransactionsVariables { address: string @@ -12,7 +12,7 @@ export enum EventTypeNames { export interface HomeExchangeFragment { __typename: EventTypeNames.Exchange - type: TransactionTypes + type: TransactionTypes.EXCHANGE hash: string inValue: number outValue: number @@ -23,7 +23,7 @@ export interface HomeExchangeFragment { export interface HomeTransferFragment { __typename: EventTypeNames.Transfer - type: TransactionTypes + type: TransferTransactionTypes hash: string value: number symbol: string diff --git a/packages/mobile/src/transactions/TransactionFeed.tsx b/packages/mobile/src/transactions/TransactionFeed.tsx index 6258573f653..3beab000217 100644 --- a/packages/mobile/src/transactions/TransactionFeed.tsx +++ b/packages/mobile/src/transactions/TransactionFeed.tsx @@ -3,7 +3,7 @@ import { ApolloError } from 'apollo-boost' import * as React from 'react' import { FlatList } from 'react-native' import { connect } from 'react-redux' -import { Event, EventTypeNames, UserTransactionsData } from 'src/apollo/types' +import { Event, UserTransactionsData } from 'src/apollo/types' import { CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' import { AddressToE164NumberType } from 'src/identity/reducer' import { Invitees, SENTINEL_INVITE_COMMENT } from 'src/invite/actions' @@ -12,7 +12,12 @@ import { recipientCacheSelector } from 'src/recipients/reducer' import { RootState } from 'src/redux/reducers' import ExchangeFeedItem from 'src/transactions/ExchangeFeedItem' import NoActivity from 'src/transactions/NoActivity' -import { StandbyTransaction, TransactionStatus, TransactionTypes } from 'src/transactions/reducer' +import { + isTransferType, + StandbyTransaction, + TransactionStatus, + TransactionTypes, +} from 'src/transactions/reducer' import TransferFeedItem from 'src/transactions/TransferFeedItem' import Logger from 'src/utils/Logger' import { privateCommentKeySelector } from 'src/web3/selectors' @@ -52,14 +57,14 @@ const mapStateToProps = (state: RootState): StateProps => ({ function exchangeFilter(tx: Event) { return ( tx !== null && - (tx.__typename === EventTypeNames.Exchange || resolveCurrency(tx.symbol) === CURRENCY_ENUM.GOLD) + (tx.type === TransactionTypes.EXCHANGE || resolveCurrency(tx.symbol) === CURRENCY_ENUM.GOLD) ) } function defaultFilter(tx: Event) { return ( tx !== null && - (tx.__typename === EventTypeNames.Exchange || resolveCurrency(tx.symbol) !== CURRENCY_ENUM.GOLD) + (tx.type === TransactionTypes.EXCHANGE || resolveCurrency(tx.symbol) !== CURRENCY_ENUM.GOLD) ) } @@ -84,11 +89,11 @@ export class TransactionFeed extends React.PureComponent { } } - // @ts-ignore - if (tx.__typename && tx.__typename === EventTypeNames.Transfer) { + if (isTransferType(tx.type)) { return ( // @ts-ignore { {...tx} /> ) - // @ts-ignore - } else if (tx.__typename && tx.__typename === EventTypeNames.Exchange) { + } else if (tx.type === TransactionTypes.EXCHANGE) { return ( - // @ts-ignore ) - } else if (tx.type && tx.type === TransactionTypes.EXCHANGE) { - // @ts-ignore + /* + } else if (tx.type === TransactionTypes.EXCHANGE) { return - } else if (tx.type) { + + } else if (tx.type) { return ( // @ts-ignore { {...tx} /> ) + */ } else { return } diff --git a/packages/mobile/src/transactions/reducer.ts b/packages/mobile/src/transactions/reducer.ts index 54809b6d867..ca33936ea32 100644 --- a/packages/mobile/src/transactions/reducer.ts +++ b/packages/mobile/src/transactions/reducer.ts @@ -49,7 +49,7 @@ export enum TransactionTypes { NETWORK_FEE = 'NETWORK_FEE', } -type TransferTransactionTypes = +export type TransferTransactionTypes = | TransactionTypes.SENT | TransactionTypes.RECEIVED | TransactionTypes.ESCROW_RECEIVED @@ -61,6 +61,24 @@ type TransferTransactionTypes = | TransactionTypes.INVITE_RECEIVED | TransactionTypes.NETWORK_FEE +export const isTransferType = (txType: TransactionTypes) => { + if ( + txType === TransactionTypes.SENT || + txType === TransactionTypes.RECEIVED || + txType === TransactionTypes.ESCROW_RECEIVED || + txType === TransactionTypes.ESCROW_SENT || + txType === TransactionTypes.FAUCET || + txType === TransactionTypes.VERIFICATION_REWARD || + txType === TransactionTypes.VERIFICATION_FEE || + txType === TransactionTypes.INVITE_SENT || + txType === TransactionTypes.INVITE_RECEIVED || + txType === TransactionTypes.NETWORK_FEE + ) { + return true + } + return false +} + export interface State { standbyTransactions: StandbyTransaction[] } diff --git a/packages/utils/src/phoneNumbers.ts b/packages/utils/src/phoneNumbers.ts index b6522d007b7..657ec8d36a7 100644 --- a/packages/utils/src/phoneNumbers.ts +++ b/packages/utils/src/phoneNumbers.ts @@ -153,7 +153,9 @@ export function parsePhoneNumber( } : null } catch (error) { - console.debug(`phoneNumbers/parsePhoneNumber/Failed to parse phone number, error: ${error}`) + console.debug( + `phoneNumbers/parsePhoneNumber/Failed to parse phone number ${phoneNumberRaw}, error: ${error}` + ) return null } } diff --git a/packages/walletkit/src/contract-utils.ts b/packages/walletkit/src/contract-utils.ts index 92d3cc163c3..7f94b9f5604 100644 --- a/packages/walletkit/src/contract-utils.ts +++ b/packages/walletkit/src/contract-utils.ts @@ -531,7 +531,10 @@ export async function sendTransactionAsyncWithWeb3Signing( } } } catch (error) { - Logger.warn(tag, `Transaction failed with error "${error.name + ' ' + error.message}"`) + Logger.warn( + tag, + `Transaction failed with error "${error.name + ' ' + JSON.stringify(error.message)}"` + ) logger(Exception(error)) rejectAll(error) } From f276c08ba346145e92240b532e8200b484ac6d61 Mon Sep 17 00:00:00 2001 From: annakaz Date: Tue, 17 Dec 2019 11:00:56 -0800 Subject: [PATCH 2/9] Delete commented out code --- .../src/transactions/TransactionFeed.tsx | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/mobile/src/transactions/TransactionFeed.tsx b/packages/mobile/src/transactions/TransactionFeed.tsx index 3beab000217..dd2b60cfd6d 100644 --- a/packages/mobile/src/transactions/TransactionFeed.tsx +++ b/packages/mobile/src/transactions/TransactionFeed.tsx @@ -57,6 +57,7 @@ const mapStateToProps = (state: RootState): StateProps => ({ function exchangeFilter(tx: Event) { return ( tx !== null && + // Show exchange and gold transactions in exchange tab feed (tx.type === TransactionTypes.EXCHANGE || resolveCurrency(tx.symbol) === CURRENCY_ENUM.GOLD) ) } @@ -64,6 +65,7 @@ function exchangeFilter(tx: Event) { function defaultFilter(tx: Event) { return ( tx !== null && + // Show exchange and stableToken transactions in home feed (tx.type === TransactionTypes.EXCHANGE || resolveCurrency(tx.symbol) !== CURRENCY_ENUM.GOLD) ) } @@ -93,7 +95,6 @@ export class TransactionFeed extends React.PureComponent { return ( // @ts-ignore { {...tx} /> ) - /* - } else if (tx.type === TransactionTypes.EXCHANGE) { - return - - } else if (tx.type) { - return ( - // @ts-ignore - - ) - */ } else { return } From 019a73a3560e6a7d1880cbe36e67767b24b53269 Mon Sep 17 00:00:00 2001 From: annakaz Date: Tue, 17 Dec 2019 11:09:12 -0800 Subject: [PATCH 3/9] Put back ts ignore --- packages/mobile/src/transactions/TransactionFeed.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mobile/src/transactions/TransactionFeed.tsx b/packages/mobile/src/transactions/TransactionFeed.tsx index dd2b60cfd6d..ebbe5589b7b 100644 --- a/packages/mobile/src/transactions/TransactionFeed.tsx +++ b/packages/mobile/src/transactions/TransactionFeed.tsx @@ -106,6 +106,7 @@ export class TransactionFeed extends React.PureComponent { ) } else if (tx.type === TransactionTypes.EXCHANGE) { return ( + // @ts-ignore Date: Tue, 17 Dec 2019 11:18:45 -0800 Subject: [PATCH 4/9] Fix lint/build errors --- packages/mobile/src/apollo/__mockData__.ts | 18 +++++++++--------- .../src/transactions/ExchangeFeedItem.test.tsx | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/mobile/src/apollo/__mockData__.ts b/packages/mobile/src/apollo/__mockData__.ts index 7ed67551a4d..71e3ce8d7dc 100644 --- a/packages/mobile/src/apollo/__mockData__.ts +++ b/packages/mobile/src/apollo/__mockData__.ts @@ -5,13 +5,13 @@ import { UserTransactionsData, } from 'src/apollo/types' import { SENTINEL_INVITE_COMMENT } from 'src/invite/actions' -import { TransactionTypes } from 'src/transactions/reducer' +import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/reducer' export const invitedAddress = '0x1b173' const exchangeDollar: HomeExchangeFragment = { __typename: EventTypeNames.Exchange, - type: 'EXCHANGE' as TransactionTypes, + type: 'EXCHANGE' as TransactionTypes.EXCHANGE, hash: '1', inValue: 19080, timestamp: Date.now(), @@ -22,7 +22,7 @@ const exchangeDollar: HomeExchangeFragment = { const exchangeGold: HomeExchangeFragment = { __typename: EventTypeNames.Exchange, - type: 'EXCHANGE' as TransactionTypes, + type: 'EXCHANGE' as TransactionTypes.EXCHANGE, hash: '1', inValue: 190, timestamp: Date.now(), @@ -33,7 +33,7 @@ const exchangeGold: HomeExchangeFragment = { const sent: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'SENT' as TransactionTypes, + type: 'SENT' as TransferTransactionTypes, value: 987161, symbol: 'Celo Gold', timestamp: Date.now(), @@ -44,7 +44,7 @@ const sent: HomeTransferFragment = { const sentInvite: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'SENT' as TransactionTypes, + type: 'SENT' as TransferTransactionTypes, value: 0.33, symbol: 'Celo Dollar', timestamp: Date.now(), @@ -55,7 +55,7 @@ const sentInvite: HomeTransferFragment = { const recieved: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'RECEIVED' as TransactionTypes, + type: 'RECEIVED' as TransferTransactionTypes, value: 587161, symbol: 'Celo Gold', timestamp: Date.now(), @@ -65,7 +65,7 @@ const recieved: HomeTransferFragment = { } const faucet: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'FAUCET' as TransactionTypes, + type: 'FAUCET' as TransferTransactionTypes, value: 387161, symbol: 'Celo Dollar', timestamp: Date.now(), @@ -75,7 +75,7 @@ const faucet: HomeTransferFragment = { } const verificationFee: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'VERIFICATION_FEE' as TransactionTypes, + type: 'VERIFICATION_FEE' as TransferTransactionTypes, value: 0.3, symbol: 'Celo Gold', timestamp: Date.now(), @@ -85,7 +85,7 @@ const verificationFee: HomeTransferFragment = { } const verificationReward: HomeTransferFragment = { __typename: EventTypeNames.Transfer, - type: 'VERIFICATION_REWARD' as TransactionTypes, + type: 'VERIFICATION_REWARD' as TransferTransactionTypes, value: 9371, symbol: 'Celo Dollar', timestamp: Date.now(), diff --git a/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx b/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx index b31364a7cb2..6c47ee20e3b 100644 --- a/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx +++ b/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx @@ -29,7 +29,7 @@ describe('ExchangeFeedItem', () => { Date: Tue, 17 Dec 2019 11:28:49 -0800 Subject: [PATCH 5/9] Fix comment tsignore --- .../src/transactions/TransactionFeed.tsx | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/mobile/src/transactions/TransactionFeed.tsx b/packages/mobile/src/transactions/TransactionFeed.tsx index ebbe5589b7b..aace1da3312 100644 --- a/packages/mobile/src/transactions/TransactionFeed.tsx +++ b/packages/mobile/src/transactions/TransactionFeed.tsx @@ -80,18 +80,26 @@ export class TransactionFeed extends React.PureComponent { }) => { const { kind, addressToE164Number, invitees, recipientCache } = this.props - if (tx.hasOwnProperty('comment')) { - // @ts-ignore - if (tx.comment === SENTINEL_INVITE_COMMENT) { - if (tx.type === TransactionTypes.SENT) { - tx.type = TransactionTypes.INVITE_SENT - } else if (tx.type === TransactionTypes.RECEIVED) { - tx.type = TransactionTypes.INVITE_RECEIVED + if (tx.type === TransactionTypes.EXCHANGE) { + return ( + // @ts-ignore + + ) + } else if (isTransferType(tx.type)) { + // Identify invite txs + if (tx.hasOwnProperty('comment')) { + if (tx.comment === SENTINEL_INVITE_COMMENT) { + if (tx.type === TransactionTypes.SENT) { + tx.type = TransactionTypes.INVITE_SENT + } else if (tx.type === TransactionTypes.RECEIVED) { + tx.type = TransactionTypes.INVITE_RECEIVED + } } } - } - - if (isTransferType(tx.type)) { return ( // @ts-ignore { {...tx} /> ) - } else if (tx.type === TransactionTypes.EXCHANGE) { - return ( - // @ts-ignore - - ) } else { + Logger.error('TransactionFeed', `Unexpected transaction type ${tx.type}`) return } } From 1386888d9d5e4cfb29e6557d765849f46f4dcc9d Mon Sep 17 00:00:00 2001 From: annakaz Date: Tue, 17 Dec 2019 12:12:56 -0800 Subject: [PATCH 6/9] Fix types --- packages/mobile/src/apollo/__mockData__.ts | 36 +++++++------------ packages/mobile/src/apollo/types.ts | 28 +++++++-------- packages/mobile/src/escrow/saga.ts | 2 +- packages/mobile/src/exchange/saga.ts | 4 +-- packages/mobile/src/stableToken/saga.test.ts | 4 +-- packages/mobile/src/tokens/saga.ts | 2 +- .../transactions/ExchangeFeedItem.test.tsx | 2 -- .../src/transactions/TransactionFeed.test.tsx | 15 ++++---- .../src/transactions/TransactionFeed.tsx | 1 - .../transactions/TransferFeedItem.test.tsx | 15 -------- packages/mobile/src/transactions/reducer.ts | 19 ++-------- 11 files changed, 42 insertions(+), 86 deletions(-) diff --git a/packages/mobile/src/apollo/__mockData__.ts b/packages/mobile/src/apollo/__mockData__.ts index 71e3ce8d7dc..4d417e81658 100644 --- a/packages/mobile/src/apollo/__mockData__.ts +++ b/packages/mobile/src/apollo/__mockData__.ts @@ -1,41 +1,34 @@ -import { - EventTypeNames, - HomeExchangeFragment, - HomeTransferFragment, - UserTransactionsData, -} from 'src/apollo/types' +import { HomeExchangeFragment, HomeTransferFragment, UserTransactionsData } from 'src/apollo/types' +import { CURRENCY_ENUM } from 'src/geth/consts' import { SENTINEL_INVITE_COMMENT } from 'src/invite/actions' import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/reducer' export const invitedAddress = '0x1b173' const exchangeDollar: HomeExchangeFragment = { - __typename: EventTypeNames.Exchange, type: 'EXCHANGE' as TransactionTypes.EXCHANGE, hash: '1', inValue: 19080, timestamp: Date.now(), - inSymbol: 'Celo Dollar', - outSymbol: 'Celo Gold', + inSymbol: 'Celo Dollar' as CURRENCY_ENUM, + outSymbol: 'Celo Gold' as CURRENCY_ENUM, outValue: 62252, } const exchangeGold: HomeExchangeFragment = { - __typename: EventTypeNames.Exchange, type: 'EXCHANGE' as TransactionTypes.EXCHANGE, hash: '1', inValue: 190, timestamp: Date.now(), - inSymbol: 'Celo Gold', - outSymbol: 'Celo Dollar', + inSymbol: 'Celo Gold' as CURRENCY_ENUM, + outSymbol: 'Celo Dollar' as CURRENCY_ENUM, outValue: 62, } const sent: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'SENT' as TransferTransactionTypes, value: 987161, - symbol: 'Celo Gold', + symbol: 'Celo Gold' as CURRENCY_ENUM, timestamp: Date.now(), address: '0x423043cca38e75d7913504fedfd1dd4539cc55b3', comment: 'FAKE FAKE FAKE', @@ -43,10 +36,9 @@ const sent: HomeTransferFragment = { } const sentInvite: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'SENT' as TransferTransactionTypes, value: 0.33, - symbol: 'Celo Dollar', + symbol: 'Celo Dollar' as CURRENCY_ENUM, timestamp: Date.now(), address: invitedAddress, comment: SENTINEL_INVITE_COMMENT, @@ -54,40 +46,36 @@ const sentInvite: HomeTransferFragment = { } const recieved: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'RECEIVED' as TransferTransactionTypes, value: 587161, - symbol: 'Celo Gold', + symbol: 'Celo Gold' as CURRENCY_ENUM, timestamp: Date.now(), address: '0x423043cca38e75d7913504fedfd1dd4539cc55b3', comment: 'FAKE FAKE FAKE', hash: '01010', } const faucet: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'FAUCET' as TransferTransactionTypes, value: 387161, - symbol: 'Celo Dollar', + symbol: 'Celo Dollar' as CURRENCY_ENUM, timestamp: Date.now(), address: '0x423043cca38e75d7913504fedfd1dd4539cc55b3', comment: 'FAKE FAKE FAKE', hash: '01010', } const verificationFee: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'VERIFICATION_FEE' as TransferTransactionTypes, value: 0.3, - symbol: 'Celo Gold', + symbol: 'Celo Gold' as CURRENCY_ENUM, timestamp: Date.now(), address: '0x423043cca38e75d7913504fedfd1dd4539cc55b3', comment: 'FAKE FAKE FAKE', hash: '01010', } const verificationReward: HomeTransferFragment = { - __typename: EventTypeNames.Transfer, type: 'VERIFICATION_REWARD' as TransferTransactionTypes, value: 9371, - symbol: 'Celo Dollar', + symbol: 'Celo Dollar' as CURRENCY_ENUM, timestamp: Date.now(), address: '0x423043cca38e75d7913504fedfd1dd4539cc55b3', comment: 'FAKE FAKE FAKE', diff --git a/packages/mobile/src/apollo/types.ts b/packages/mobile/src/apollo/types.ts index eebb990730b..db9df7c25a6 100644 --- a/packages/mobile/src/apollo/types.ts +++ b/packages/mobile/src/apollo/types.ts @@ -1,38 +1,38 @@ import { Query } from 'react-apollo' +import { CURRENCY_ENUM } from 'src/geth/consts' import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/reducer' export interface UserTransactionsVariables { address: string } -export enum EventTypeNames { - Exchange = 'Exchange', - Transfer = 'Transfer', -} - -export interface HomeExchangeFragment { - __typename: EventTypeNames.Exchange +export interface ExchangeTransaction { type: TransactionTypes.EXCHANGE - hash: string inValue: number outValue: number - inSymbol: string - outSymbol: string + inSymbol: CURRENCY_ENUM + outSymbol: CURRENCY_ENUM timestamp: number } -export interface HomeTransferFragment { - __typename: EventTypeNames.Transfer +export interface TransferTransaction { type: TransferTransactionTypes - hash: string value: number - symbol: string + symbol: CURRENCY_ENUM timestamp: number address: string comment: string // TODO: fee needs to be added here } +export interface HomeExchangeFragment extends ExchangeTransaction { + hash: string +} + +export interface HomeTransferFragment extends TransferTransaction { + hash: string +} + export type Event = HomeExchangeFragment | HomeTransferFragment export interface UserTransactionsData { events?: Event[] | null diff --git a/packages/mobile/src/escrow/saga.ts b/packages/mobile/src/escrow/saga.ts index 92861b08953..fb416272bc9 100644 --- a/packages/mobile/src/escrow/saga.ts +++ b/packages/mobile/src/escrow/saga.ts @@ -86,7 +86,7 @@ function* registerStandbyTransaction(id: string, value: string, address: string) id, type: TransactionTypes.ESCROW_SENT, status: TransactionStatus.Pending, - value, + value: +value, symbol: CURRENCY_ENUM.DOLLAR, timestamp: Math.floor(Date.now() / 1000), address, diff --git a/packages/mobile/src/exchange/saga.ts b/packages/mobile/src/exchange/saga.ts index f903c63207a..773b50cfa37 100644 --- a/packages/mobile/src/exchange/saga.ts +++ b/packages/mobile/src/exchange/saga.ts @@ -235,9 +235,9 @@ function* createStandbyTx( type: TransactionTypes.EXCHANGE, status: TransactionStatus.Pending, inSymbol: makerToken, - inValue: makerAmount.toString(), + inValue: makerAmount.toNumber(), outSymbol: makerToken === CURRENCY_ENUM.DOLLAR ? CURRENCY_ENUM.GOLD : CURRENCY_ENUM.DOLLAR, - outValue: takerAmount.toString(), + outValue: takerAmount.toNumber(), timestamp: Math.floor(Date.now() / 1000), }) ) diff --git a/packages/mobile/src/stableToken/saga.test.ts b/packages/mobile/src/stableToken/saga.test.ts index d21c9269c57..29415592eda 100644 --- a/packages/mobile/src/stableToken/saga.test.ts +++ b/packages/mobile/src/stableToken/saga.test.ts @@ -77,7 +77,7 @@ describe('stableToken saga', () => { type: TransactionTypes.SENT, comment: COMMENT, status: TransactionStatus.Pending, - value: BALANCE, + value: +BALANCE, symbol: CURRENCY_ENUM.DOLLAR, timestamp: Math.floor(Date.now() / 1000), address: mockAccount, @@ -97,7 +97,7 @@ describe('stableToken saga', () => { type: TransactionTypes.SENT, comment: COMMENT, status: TransactionStatus.Pending, - value: BALANCE, + value: +BALANCE, symbol: CURRENCY_ENUM.DOLLAR, timestamp: Math.floor(Date.now() / 1000), address: mockAccount, diff --git a/packages/mobile/src/tokens/saga.ts b/packages/mobile/src/tokens/saga.ts index 811e344c35a..ee757490b46 100644 --- a/packages/mobile/src/tokens/saga.ts +++ b/packages/mobile/src/tokens/saga.ts @@ -158,7 +158,7 @@ export function tokenTransferFactory({ type: TransactionTypes.SENT, comment, status: TransactionStatus.Pending, - value: amount.toString(), + value: +amount, symbol: currency, timestamp: Math.floor(Date.now() / 1000), address: recipientAddress, diff --git a/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx b/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx index 6c47ee20e3b..c1b7c04a72d 100644 --- a/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx +++ b/packages/mobile/src/transactions/ExchangeFeedItem.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react' import 'react-native' import { Provider } from 'react-redux' import * as renderer from 'react-test-renderer' -import { EventTypeNames } from 'src/apollo/types' import { CURRENCY_ENUM } from 'src/geth/consts' import { ExchangeFeedItem } from 'src/transactions/ExchangeFeedItem' import { TransactionStatus, TransactionTypes } from 'src/transactions/reducer' @@ -28,7 +27,6 @@ describe('ExchangeFeedItem', () => { { if (tx.type === TransactionTypes.EXCHANGE) { return ( - // @ts-ignore { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( { const tree = renderer.create( Date: Tue, 17 Dec 2019 12:16:39 -0800 Subject: [PATCH 7/9] Upate snapshots --- .../TransactionFeed.test.tsx.snap | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap b/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap index aa956d2d221..ffafb76960e 100644 --- a/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap +++ b/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap @@ -120,14 +120,14 @@ exports[`renders for gold to dollar exchange properly 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "SENT", - "value": "100", + "value": 100, }, Object { "id": "0112", "inSymbol": "Celo Dollar", - "inValue": "20", + "inValue": 20, "outSymbol": "Celo Gold", - "outValue": "30", + "outValue": 30, "status": "Pending", "timestamp": 1542409112, "type": "EXCHANGE", @@ -140,10 +140,9 @@ exports[`renders for gold to dollar exchange properly 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "NETWORK_FEE", - "value": "0.0001", + "value": 0.0001, }, Object { - "__typename": "Exchange", "hash": "0x00000000000000000000", "inSymbol": "Celo Dollar", "inValue": 30, @@ -978,14 +977,14 @@ exports[`renders for loading 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "SENT", - "value": "100", + "value": 100, }, Object { "id": "0112", "inSymbol": "Celo Dollar", - "inValue": "20", + "inValue": 20, "outSymbol": "Celo Gold", - "outValue": "30", + "outValue": 30, "status": "Pending", "timestamp": 1542409112, "type": "EXCHANGE", @@ -998,7 +997,7 @@ exports[`renders for loading 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "NETWORK_FEE", - "value": "0.0001", + "value": 0.0001, }, ] } @@ -1620,14 +1619,14 @@ exports[`renders for no transactions 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "SENT", - "value": "100", + "value": 100, }, Object { "id": "0112", "inSymbol": "Celo Dollar", - "inValue": "20", + "inValue": 20, "outSymbol": "Celo Gold", - "outValue": "30", + "outValue": 30, "status": "Pending", "timestamp": 1542409112, "type": "EXCHANGE", @@ -1640,7 +1639,7 @@ exports[`renders for no transactions 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "NETWORK_FEE", - "value": "0.0001", + "value": 0.0001, }, ] } @@ -2262,14 +2261,14 @@ exports[`renders for standbyTransactions 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "SENT", - "value": "100", + "value": 100, }, Object { "id": "0112", "inSymbol": "Celo Dollar", - "inValue": "20", + "inValue": 20, "outSymbol": "Celo Gold", - "outValue": "30", + "outValue": 30, "status": "Pending", "timestamp": 1542409112, "type": "EXCHANGE", @@ -2282,7 +2281,7 @@ exports[`renders for standbyTransactions 1`] = ` "symbol": "Celo Dollar", "timestamp": 1542406112, "type": "NETWORK_FEE", - "value": "0.0001", + "value": 0.0001, }, ] } From 10e2411ff68c97829a5a1d3e1b74fe24e0c1ef23 Mon Sep 17 00:00:00 2001 From: annakaz Date: Tue, 17 Dec 2019 14:06:42 -0800 Subject: [PATCH 8/9] Replace Event with Transaction type --- packages/mobile/src/apollo/types.ts | 16 ++++++++++--- packages/mobile/src/home/TransactionsList.tsx | 4 ++-- .../src/transactions/TransactionFeed.tsx | 23 +++++++++++-------- packages/mobile/src/transactions/reducer.ts | 2 -- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/packages/mobile/src/apollo/types.ts b/packages/mobile/src/apollo/types.ts index db9df7c25a6..0962f3f9aa1 100644 --- a/packages/mobile/src/apollo/types.ts +++ b/packages/mobile/src/apollo/types.ts @@ -1,6 +1,10 @@ import { Query } from 'react-apollo' import { CURRENCY_ENUM } from 'src/geth/consts' -import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/reducer' +import { + TransactionStatus, + TransactionTypes, + TransferTransactionTypes, +} from 'src/transactions/reducer' export interface UserTransactionsVariables { address: string @@ -8,20 +12,26 @@ export interface UserTransactionsVariables { export interface ExchangeTransaction { type: TransactionTypes.EXCHANGE + id?: string + hash?: string inValue: number outValue: number inSymbol: CURRENCY_ENUM outSymbol: CURRENCY_ENUM timestamp: number + status?: TransactionStatus } export interface TransferTransaction { type: TransferTransactionTypes + id?: string + hash?: string value: number symbol: CURRENCY_ENUM timestamp: number address: string comment: string + status?: TransactionStatus // TODO: fee needs to be added here } @@ -33,9 +43,9 @@ export interface HomeTransferFragment extends TransferTransaction { hash: string } -export type Event = HomeExchangeFragment | HomeTransferFragment +export type Transaction = ExchangeTransaction | TransferTransaction export interface UserTransactionsData { - events?: Event[] | null + events?: Transaction[] | null } export default class UserTransactionsQuery extends Query< diff --git a/packages/mobile/src/home/TransactionsList.tsx b/packages/mobile/src/home/TransactionsList.tsx index 7bae516db7b..becc1d7838e 100644 --- a/packages/mobile/src/home/TransactionsList.tsx +++ b/packages/mobile/src/home/TransactionsList.tsx @@ -3,7 +3,7 @@ import * as React from 'react' import { WithNamespaces, withNamespaces } from 'react-i18next' import { connect } from 'react-redux' import componentWithAnalytics from 'src/analytics/wrapper' -import UserTransactionsQuery, { Event, UserTransactionsData } from 'src/apollo/types' +import UserTransactionsQuery, { Transaction, UserTransactionsData } from 'src/apollo/types' import { Namespaces } from 'src/i18n' import { RootState } from 'src/redux/reducers' import { removeStandbyTransaction } from 'src/transactions/actions' @@ -77,7 +77,7 @@ export class TransactionsList extends React.PureComponent { } const events = data.events - const queryDataTxIDs = new Set(events.map((event: Event) => event.hash)) + const queryDataTxIDs = new Set(events.map((event: Transaction) => event.hash)) const inQueryTxs = (tx: StandbyTransaction) => tx.hash && queryDataTxIDs.has(tx.hash) && tx.status !== TransactionStatus.Failed const filteredStandbyTxs = this.props.standbyTransactions.filter(inQueryTxs) diff --git a/packages/mobile/src/transactions/TransactionFeed.tsx b/packages/mobile/src/transactions/TransactionFeed.tsx index 127820dc2ee..1b35d7cb609 100644 --- a/packages/mobile/src/transactions/TransactionFeed.tsx +++ b/packages/mobile/src/transactions/TransactionFeed.tsx @@ -3,7 +3,12 @@ import { ApolloError } from 'apollo-boost' import * as React from 'react' import { FlatList } from 'react-native' import { connect } from 'react-redux' -import { Event, UserTransactionsData } from 'src/apollo/types' +import { + ExchangeTransaction, + Transaction, + TransferTransaction, + UserTransactionsData, +} from 'src/apollo/types' import { CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' import { AddressToE164NumberType } from 'src/identity/reducer' import { Invitees, SENTINEL_INVITE_COMMENT } from 'src/invite/actions' @@ -54,7 +59,7 @@ const mapStateToProps = (state: RootState): StateProps => ({ recipientCache: recipientCacheSelector(state), }) -function exchangeFilter(tx: Event) { +function exchangeFilter(tx: Transaction) { return ( tx !== null && // Show exchange and gold transactions in exchange tab feed @@ -62,7 +67,7 @@ function exchangeFilter(tx: Event) { ) } -function defaultFilter(tx: Event) { +function defaultFilter(tx: Transaction) { return ( tx !== null && // Show exchange and stableToken transactions in home feed @@ -71,11 +76,10 @@ function defaultFilter(tx: Event) { } export class TransactionFeed extends React.PureComponent { - // TODO(cmcewen): Clean this up. Standby txs should have the same data shape renderItem = (commentKeyBuffer: Buffer | null) => ({ item: tx, }: { - item: Event | StandbyTransaction + item: ExchangeTransaction | TransferTransaction index: number }) => { const { kind, addressToE164Number, invitees, recipientCache } = this.props @@ -83,7 +87,7 @@ export class TransactionFeed extends React.PureComponent { if (tx.type === TransactionTypes.EXCHANGE) { return ( @@ -100,9 +104,8 @@ export class TransactionFeed extends React.PureComponent { } } return ( - // @ts-ignore { } } - keyExtractor = (item: Event | StandbyTransaction) => { + keyExtractor = (item: Transaction) => { return item.hash + item.timestamp.toString() } @@ -148,7 +151,7 @@ export class TransactionFeed extends React.PureComponent { const events = (data && data.events) || [] const commentKeyBuffer = commentKey ? Buffer.from(commentKey, 'hex') : null - const queryDataTxIDs = new Set(events.map((event: Event) => event.hash)) + const queryDataTxIDs = new Set(events.map((event: Transaction) => event.hash)) const notInQueryTxs = (tx: StandbyTransaction) => !queryDataTxIDs.has(tx.id) && tx.status !== TransactionStatus.Failed let filteredStandbyTxs = standbyTransactions.filter(notInQueryTxs) diff --git a/packages/mobile/src/transactions/reducer.ts b/packages/mobile/src/transactions/reducer.ts index 31c7715afb6..64ee454f5d4 100644 --- a/packages/mobile/src/transactions/reducer.ts +++ b/packages/mobile/src/transactions/reducer.ts @@ -4,12 +4,10 @@ import { Actions, ActionTypes } from 'src/transactions/actions' export interface ExchangeStandby extends ExchangeTransaction { id: string status: TransactionStatus - hash?: string } export interface TransferStandby extends TransferTransaction { id: string status: TransactionStatus - hash?: string } export type StandbyTransaction = ExchangeStandby | TransferStandby From a52e86a638d030ff8cc5fa3be1a1b24b4c432770 Mon Sep 17 00:00:00 2001 From: annakaz Date: Wed, 18 Dec 2019 12:24:57 -0800 Subject: [PATCH 9/9] Use enum in mockdata and remove phone number --- packages/mobile/src/apollo/__mockData__.ts | 12 ++++++------ packages/utils/src/phoneNumbers.ts | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/mobile/src/apollo/__mockData__.ts b/packages/mobile/src/apollo/__mockData__.ts index 4d417e81658..76c579e8045 100644 --- a/packages/mobile/src/apollo/__mockData__.ts +++ b/packages/mobile/src/apollo/__mockData__.ts @@ -6,7 +6,7 @@ import { TransactionTypes, TransferTransactionTypes } from 'src/transactions/red export const invitedAddress = '0x1b173' const exchangeDollar: HomeExchangeFragment = { - type: 'EXCHANGE' as TransactionTypes.EXCHANGE, + type: TransactionTypes.EXCHANGE, hash: '1', inValue: 19080, timestamp: Date.now(), @@ -16,7 +16,7 @@ const exchangeDollar: HomeExchangeFragment = { } const exchangeGold: HomeExchangeFragment = { - type: 'EXCHANGE' as TransactionTypes.EXCHANGE, + type: TransactionTypes.EXCHANGE, hash: '1', inValue: 190, timestamp: Date.now(), @@ -26,7 +26,7 @@ const exchangeGold: HomeExchangeFragment = { } const sent: HomeTransferFragment = { - type: 'SENT' as TransferTransactionTypes, + type: TransactionTypes.SENT, value: 987161, symbol: 'Celo Gold' as CURRENCY_ENUM, timestamp: Date.now(), @@ -36,7 +36,7 @@ const sent: HomeTransferFragment = { } const sentInvite: HomeTransferFragment = { - type: 'SENT' as TransferTransactionTypes, + type: TransactionTypes.SENT, value: 0.33, symbol: 'Celo Dollar' as CURRENCY_ENUM, timestamp: Date.now(), @@ -46,7 +46,7 @@ const sentInvite: HomeTransferFragment = { } const recieved: HomeTransferFragment = { - type: 'RECEIVED' as TransferTransactionTypes, + type: TransactionTypes.RECEIVED, value: 587161, symbol: 'Celo Gold' as CURRENCY_ENUM, timestamp: Date.now(), @@ -55,7 +55,7 @@ const recieved: HomeTransferFragment = { hash: '01010', } const faucet: HomeTransferFragment = { - type: 'FAUCET' as TransferTransactionTypes, + type: TransactionTypes.FAUCET, value: 387161, symbol: 'Celo Dollar' as CURRENCY_ENUM, timestamp: Date.now(), diff --git a/packages/utils/src/phoneNumbers.ts b/packages/utils/src/phoneNumbers.ts index 657ec8d36a7..b6522d007b7 100644 --- a/packages/utils/src/phoneNumbers.ts +++ b/packages/utils/src/phoneNumbers.ts @@ -153,9 +153,7 @@ export function parsePhoneNumber( } : null } catch (error) { - console.debug( - `phoneNumbers/parsePhoneNumber/Failed to parse phone number ${phoneNumberRaw}, error: ${error}` - ) + console.debug(`phoneNumbers/parsePhoneNumber/Failed to parse phone number, error: ${error}`) return null } }