-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transfers): Remove old feature flag, support tokenId in transfer…
… feed and CICO (#4275) ### Description This PR cleans up an old hacky feature flag we had laying around, and in the process adds support for native tokens to appear _correctly_ in the transfer feed. This also has the effect of refactoring some of our CICO code to support tokenIds as well, in order to use the new `TokenDisplay` component in the case of `ETH` being selected. ### Test plan Unit and manual tested. See video below for ETH information showing up where it previously was not (namely: transfer feed items, transfer feed details page, CICO header balance). The second video shows the existing behavior, where ETH is kinda broken all over the place. https://github.com/valora-inc/wallet/assets/569401/c7931d12-87a2-42a6-80de-516a18a343b8 https://github.com/valora-inc/wallet/assets/569401/b2bbb8e3-cee1-467b-85da-d7ce3ab0690c ### Related issues N/A ### Backwards compatibility Yes.
- Loading branch information
Showing
52 changed files
with
428 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { render } from '@testing-library/react-native' | ||
import BigNumber from 'bignumber.js' | ||
import * as React from 'react' | ||
import 'react-native' | ||
import { Provider } from 'react-redux' | ||
import LegacyTokenTotalLineItem from 'src/components/LegacyTokenTotalLineItem' | ||
import { LocalCurrencyCode } from 'src/localCurrency/consts' | ||
import { LocalAmount, NetworkId } from 'src/transactions/types' | ||
import { createMockStore, getElementText } from 'test/utils' | ||
import { mockCusdAddress, mockCusdTokenId } from 'test/values' | ||
|
||
const mockBtcAddress = '0xbtc' | ||
const mockBtcTokenId = `celo-alfajores:${mockBtcAddress}` | ||
|
||
const defaultAmount = new BigNumber(10) | ||
const defaultTokenAddress = mockCusdAddress | ||
|
||
// This component is primarily tested via TokenTotalLineItem.test.tsx | ||
describe('LegacyTokenTotalLineItem', () => { | ||
function renderComponent({ | ||
amount = defaultAmount, | ||
tokenAddress = defaultTokenAddress, | ||
localAmount, | ||
localCurrencyCode = LocalCurrencyCode.BRL, | ||
usdToLocalRate = '1.5', | ||
feeToAddInUsd = undefined, | ||
hideSign = undefined, | ||
}: { | ||
amount?: BigNumber | ||
tokenAddress?: string | ||
localAmount?: LocalAmount | ||
localCurrencyCode?: LocalCurrencyCode | ||
usdToLocalRate?: string | ||
feeToAddInUsd?: BigNumber | ||
hideSign?: boolean | ||
}) { | ||
return render( | ||
<Provider | ||
store={createMockStore({ | ||
localCurrency: { | ||
preferredCurrencyCode: LocalCurrencyCode.BRL, | ||
fetchedCurrencyCode: LocalCurrencyCode.BRL, | ||
usdToLocalRate, | ||
}, | ||
tokens: { | ||
tokenBalances: { | ||
[mockCusdTokenId]: { | ||
networkId: NetworkId['celo-alfajores'], | ||
address: mockCusdAddress, | ||
tokenId: mockCusdTokenId, | ||
symbol: 'cUSD', | ||
priceUsd: '1', | ||
balance: '10', | ||
priceFetchedAt: Date.now(), | ||
}, | ||
[mockBtcTokenId]: { | ||
networkId: NetworkId['celo-alfajores'], | ||
address: mockBtcAddress, | ||
tokenId: mockBtcTokenId, | ||
symbol: 'WBTC', | ||
priceUsd: '65000', | ||
balance: '0.5', | ||
priceFetchedAt: Date.now(), | ||
}, | ||
}, | ||
}, | ||
})} | ||
> | ||
<LegacyTokenTotalLineItem | ||
tokenAmount={amount} | ||
tokenAddress={tokenAddress} | ||
localAmount={localAmount} | ||
feeToAddInUsd={feeToAddInUsd} | ||
hideSign={hideSign} | ||
/> | ||
</Provider> | ||
) | ||
} | ||
|
||
describe('When rendering normally', () => { | ||
it('shows the right amounts', () => { | ||
const { getByTestId } = renderComponent({}) | ||
expect(getElementText(getByTestId('TotalLineItem/Total'))).toEqual('R$15.00') | ||
expect(getElementText(getByTestId('TotalLineItem/ExchangeRate'))).toEqual( | ||
'tokenExchanteRate, {"symbol":"cUSD"}R$1.50' | ||
) | ||
expect(getElementText(getByTestId('TotalLineItem/Subtotal'))).toEqual('10.00 cUSD') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import BigNumber from 'bignumber.js' | ||
import * as React from 'react' | ||
import { useTokenInfoByAddress } from 'src/tokens/hooks' | ||
import TokenTotalLineItem from 'src/components/TokenTotalLineItem' | ||
import { LocalAmount } from 'src/transactions/types' | ||
|
||
interface Props { | ||
tokenAmount: BigNumber | ||
tokenAddress?: string | ||
localAmount?: LocalAmount | ||
feeToAddInUsd?: BigNumber | undefined | ||
hideSign?: boolean | ||
title?: string | null | ||
} | ||
|
||
/** | ||
* @deprecated Use TokenTotalLineItem instead | ||
*/ | ||
export default function LegacyTokenTotalLineItem({ | ||
tokenAmount, | ||
tokenAddress, | ||
localAmount, | ||
feeToAddInUsd, | ||
hideSign, | ||
title, | ||
}: Props) { | ||
const tokenInfo = useTokenInfoByAddress(tokenAddress) | ||
return ( | ||
<TokenTotalLineItem | ||
tokenAmount={tokenAmount} | ||
tokenId={tokenInfo?.tokenId} | ||
localAmount={localAmount} | ||
feeToAddInUsd={feeToAddInUsd} | ||
hideSign={hideSign} | ||
title={title} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.