From 1ec9580a8f1e03d55a5b9792c229ea6fcf7b1fe6 Mon Sep 17 00:00:00 2001 From: JJ Adonis Date: Sun, 21 Nov 2021 11:31:26 +0800 Subject: [PATCH] `payback loan` (#1370) * initial design * updates --- mobile-app/app/components/FeeInfoRow.tsx | 2 +- .../screens/Loans/LoansNavigator.tsx | 38 ++- .../Loans/VaultDetail/VaultDetailScreen.tsx | 2 +- .../VaultDetail/components/DetailsTab.tsx | 2 +- .../Loans/VaultDetail/components/LoansTab.tsx | 62 ++-- .../components/AddOrRemoveCollateralForm.tsx | 5 +- .../screens/Loans/components/VaultCard.tsx | 8 +- .../screens/Loans/components/Vaults.tsx | 6 +- .../__snapshots__/VaultCard.test.tsx.snap | 83 +---- .../screens/Loans/hooks/CollateralPrice.ts | 6 + .../Loans/screens/BorrowLoanTokenScreen.tsx | 30 +- .../screens/ConfirmBorrowLoanTokenScreen.tsx | 40 ++- .../screens/ConfirmEditCollateralScreen.tsx | 2 +- .../screens/ConfirmPaybackLoanScreen.tsx | 278 +++++++++++++++ .../Loans/screens/EditCollateralScreen.tsx | 12 +- .../Loans/screens/PaybackLoanScreen.tsx | 317 ++++++++++++++++++ shared/translations/languages/de.json | 119 ++++++- shared/translations/languages/zh-Hans.json | 6 +- shared/translations/languages/zh-Hant.json | 6 +- 19 files changed, 843 insertions(+), 181 deletions(-) create mode 100644 mobile-app/app/screens/AppNavigator/screens/Loans/screens/ConfirmPaybackLoanScreen.tsx create mode 100644 mobile-app/app/screens/AppNavigator/screens/Loans/screens/PaybackLoanScreen.tsx diff --git a/mobile-app/app/components/FeeInfoRow.tsx b/mobile-app/app/components/FeeInfoRow.tsx index a9e4a7940a..57b7e3ca44 100644 --- a/mobile-app/app/components/FeeInfoRow.tsx +++ b/mobile-app/app/components/FeeInfoRow.tsx @@ -34,7 +34,7 @@ export function FeeInfoRow (props: FeeInfoRowProps): JSX.Element { - {translate('components/FeeInfoRow', props.type === 'ESTIMATED_FEE' ? estimatedFee.title : vaultFee.title)} + {translate('components/BottomSheetInfo', props.type === 'ESTIMATED_FEE' ? estimatedFee.title : vaultFee.title)} diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/LoansNavigator.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/LoansNavigator.tsx index 2e3bff7de4..7e29afca4f 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/LoansNavigator.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/LoansNavigator.tsx @@ -2,7 +2,7 @@ import { createStackNavigator } from '@react-navigation/stack' import * as React from 'react' import { HeaderFont } from '@components/Text' import { HeaderTitle } from '@components/HeaderTitle' -import { LoanScheme, LoanToken, LoanVaultActive } from '@defichain/whale-api-client/dist/api/loan' +import { LoanScheme, LoanToken, LoanVaultActive, LoanVaultTokenAmount } from '@defichain/whale-api-client/dist/api/loan' import { translate } from '@translations' import { NetworkDetails } from '../Settings/screens/NetworkDetails' import { LoadingState, LoansScreen } from './LoansScreen' @@ -23,6 +23,8 @@ import { tailwind } from '@tailwind' import { TokenData } from '@defichain/whale-api-client/dist/api/tokens' import { LoansFaq } from '@screens/WalletNavigator/screens/CreateWallet/LoansFaq' import { TabKey } from '@screens/AppNavigator/screens/Loans/VaultDetail/components/VaultDetailTabSection' +import { PaybackLoanScreen } from '@screens/AppNavigator/screens/Loans/screens/PaybackLoanScreen' +import { ConfirmPaybackLoanScreen } from '@screens/AppNavigator/screens/Loans/screens/ConfirmPaybackLoanScreen' export interface LoanParamList { LoansScreen: { @@ -68,6 +70,16 @@ export interface LoanParamList { fee: BigNumber conversion?: ConversionParam } + PaybackLoanScreen: { + loanToken: LoanVaultTokenAmount + vault: LoanVaultActive + } + ConfirmPaybackLoanScreen: { + fee: BigNumber + amountToPay: BigNumber + vault: LoanVaultActive + loanToken: LoanVaultTokenAmount + } [key: string]: undefined | object } @@ -231,6 +243,30 @@ export function LoansNavigator (): JSX.Element { headerBackTitleVisible: false }} /> + ( + + ) + }} + /> + ( + + ) + }} + /> ) } diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/VaultDetailScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/VaultDetailScreen.tsx index ff5907999c..3a5095d7a9 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/VaultDetailScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/VaultDetailScreen.tsx @@ -201,7 +201,7 @@ function VaultInfoSection (props: { vault?: LoanVault }): JSX.Element | null { /> diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/components/DetailsTab.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/components/DetailsTab.tsx index 9a2f057ba8..55f60352f1 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/components/DetailsTab.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/VaultDetail/components/DetailsTab.tsx @@ -121,7 +121,7 @@ function CollateralizationRatioSection (props: CollateralizationRatioSectionProp /> )} )) ) @@ -52,6 +60,8 @@ export function LoansTab (props: { vault: LoanVault }): JSX.Element { amount={loan.amount} interestAmount={vault.interestAmounts.find(interest => interest.symbol === loan.symbol)?.amount} vaultState={vault.state} + vault={vault} + loanToken={loan} /> )) )} @@ -118,16 +128,22 @@ function LoanCard (props: LoanCardProps): JSX.Element { /> )} - + + { + props.vaultState !== LoanVaultState.IN_LIQUIDATION && props.vault !== undefined && ( + + ) + } ) } // TODO: show button when payback is ready -function ActionButtons (props: { hide: boolean }): JSX.Element { - if (props.hide) { - return <> - } +function ActionButtons ({ + vault, + loanToken +}: { vault: LoanVaultActive, loanToken: LoanVaultTokenAmount }): JSX.Element { + const navigation = useNavigation>() return ( { /* TODO: handle repay loan on press */ - }} - /> - { /* TODO: handle borrow more on press */ + onPress={() => { + navigation.navigate({ + name: 'PaybackLoanScreen', + merge: true, + params: { + vault, + loanToken + } + }) }} /> - { /* TODO: handle ... on press */ - }} - > - - - ) } diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/components/AddOrRemoveCollateralForm.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/components/AddOrRemoveCollateralForm.tsx index cd9b5731d3..b1ff3b990c 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/components/AddOrRemoveCollateralForm.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/components/AddOrRemoveCollateralForm.tsx @@ -91,9 +91,8 @@ export const AddOrRemoveCollateralForm = React.memo(({ route }: Props): JSX.Elem > - {translate('components/AddOrRemoveCollateralForm', 'How much {{symbol}} to {{operation}}?', { - symbol: token.displaySymbol, - operation: isAdd ? 'add' : 'remove' + {translate('components/AddOrRemoveCollateralForm', `How much {{symbol}} to ${isAdd ? 'add' : 'remove'}?`, { + symbol: token.displaySymbol })} {onCloseButtonPress !== undefined && ( diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/components/VaultCard.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/components/VaultCard.tsx index 773cf30662..0b123d1d19 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/components/VaultCard.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/components/VaultCard.tsx @@ -152,7 +152,7 @@ export function VaultCard (props: VaultCardProps): JSX.Element { testID={`${props.testID}_total_loan`} prefix='$' value={new BigNumber(vault.loanValue).toFixed(2)} - lhs={translate('components/VaultCard', 'Total loan (USD)')} + lhs={translate('components/VaultCard', 'Total loans (USD)')} /> { navigation.navigate('VaultDetailScreen', { @@ -199,10 +196,7 @@ function VaultActionButton ({ ) } { navigation.navigate({ diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/components/Vaults.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/components/Vaults.tsx index 17b54f2d93..47031378cb 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/components/Vaults.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/components/Vaults.tsx @@ -9,7 +9,7 @@ import { translate } from '@translations' import { useDispatch, useSelector } from 'react-redux' import { RootState } from '@store' import { useEffect } from 'react' -import { fetchVaults } from '@store/loans' +import { fetchCollateralTokens, fetchVaults } from '@store/loans' import { useWhaleApiClient } from '@shared-contexts/WhaleContext' import { useWalletContext } from '@shared-contexts/WalletContext' @@ -23,6 +23,10 @@ export function Vaults (): JSX.Element { useEffect(() => { dispatch(fetchVaults({ address, client })) }, [blockCount]) + + useEffect(() => { + dispatch(fetchCollateralTokens({ client })) + }, []) const { isBetaFeature } = useFeatureFlagContext() return ( diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/components/__snapshots__/VaultCard.test.tsx.snap b/mobile-app/app/screens/AppNavigator/screens/Loans/components/__snapshots__/VaultCard.test.tsx.snap index 5404a923c4..6ed3c93443 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/components/__snapshots__/VaultCard.test.tsx.snap +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/components/__snapshots__/VaultCard.test.tsx.snap @@ -767,7 +767,7 @@ exports[`Vault card should match snapshot of active vault 1`] = ` } testID="vault_total_loan_label" > - Total loan (USD) + Total loans (USD) - -  - - Total loan (USD) + Total loans (USD) - -  - - Total loan (USD) + Total loans (USD) - -  - - Total loan (USD) + Total loans (USD) )}