-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fee estimation for Withdrawing CELO and pay for Withdrawing and Selling CELO fees in CELO #5345
Changes from all commits
e1218a0
ee4faf4
4274aac
c830b74
b7d9d9a
750d1f6
dc240a9
00fd474
2d614f0
cea9876
9150ae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | |
import AccountAddressInput from 'src/components/AccountAddressInput' | ||
import CeloAmountInput from 'src/components/CeloAmountInput' | ||
import { exchangeRatePairSelector } from 'src/exchange/reducer' | ||
import { FeeType } from 'src/fees/actions' | ||
import { useSendFee } from 'src/fees/CalculateFee' | ||
import { CURRENCY_ENUM } from 'src/geth/consts' | ||
import i18n, { Namespaces } from 'src/i18n' | ||
import { HeaderTitleWithBalance, headerWithBackButton } from 'src/navigator/Headers' | ||
|
@@ -27,9 +29,12 @@ import { StackParamList } from 'src/navigator/types' | |
import useSelector from 'src/redux/useSelector' | ||
import { useDailyTransferLimitValidator } from 'src/send/utils' | ||
import DisconnectBanner from 'src/shared/DisconnectBanner' | ||
import { divideByWei } from 'src/utils/formatting' | ||
|
||
type Props = StackScreenProps<StackParamList, Screens.WithdrawCeloScreen> | ||
|
||
const RANDOM_ADDRESS = '0xDCE9762d6C1fe89FF4f3857832131Ca18eE15C66' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have an address here yet to do the estimation, and estimating requires an address, so I used a random one. Could that cause any issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, we already do this here as well. |
||
|
||
function WithdrawCeloScreen({ navigation }: Props) { | ||
const [accountAddress, setAccountAddress] = useState('') | ||
const [celoInput, setCeloToTransfer] = useState('') | ||
|
@@ -51,6 +56,16 @@ function WithdrawCeloScreen({ navigation }: Props) { | |
CURRENCY_ENUM.GOLD | ||
) | ||
|
||
const { result } = useSendFee({ | ||
feeType: FeeType.SEND, | ||
account: RANDOM_ADDRESS, | ||
currency: CURRENCY_ENUM.GOLD, | ||
recipientAddress: RANDOM_ADDRESS, | ||
amount: goldBalance || '0', | ||
includeDekFee: false, | ||
}) | ||
const feeEstimate = result && divideByWei(result) | ||
|
||
const onConfirm = async () => { | ||
if (isTransferLimitReached) { | ||
showLimitReachedBanner() | ||
|
@@ -63,6 +78,7 @@ function WithdrawCeloScreen({ navigation }: Props) { | |
navigation.navigate(Screens.WithdrawCeloReviewScreen, { | ||
amount: celoToTransfer, | ||
recipientAddress: accountAddress, | ||
feeEstimate: feeEstimate || new BigNumber(0), | ||
}) | ||
} | ||
|
||
|
@@ -86,6 +102,7 @@ function WithdrawCeloScreen({ navigation }: Props) { | |
inputStyle={styles.input} | ||
onCeloChanged={setCeloToTransfer} | ||
celo={celoInput} | ||
feeEstimate={feeEstimate} | ||
/> | ||
</KeyboardAwareScrollView> | ||
<Button | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,7 +321,7 @@ exports[`WithdrawCeloReviewScreen renders correctly 1`] = ` | |
> | ||
|
||
|
||
0 | ||
1 | ||
</Text> | ||
</Text> | ||
</View> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,7 +213,7 @@ exports[`WithdrawCeloSummary renders correctly 1`] = ` | |
> | ||
|
||
|
||
0 | ||
1 | ||
</Text> | ||
</Text> | ||
</View> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this 1 wei, and if so, is that displayed to the user at all? If the fee was actually 1 wei, it would likely not be significant enough to warrant mentioning (unless they are trying to withdraw 100% of their balance, in which case we might help craft a request that won't leave any dust behind.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing! The wei to CELO mapping happens in
WithdrawCeloScreen
, line 67. The converted fee is then passed to this review screen and this is a test of it where I put a != 0 number just to have something there.