-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stx send form high fee warning, closes #5362
- Loading branch information
1 parent
b03d6af
commit 0af3ae9
Showing
16 changed files
with
173 additions
and
116 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
51 changes: 51 additions & 0 deletions
51
src/app/features/stacks-high-fee-warning/stacks-high-fee-warning-container.tsx
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,51 @@ | ||
import { createContext, useContext, useState } from 'react'; | ||
|
||
import BigNumber from 'bignumber.js'; | ||
import type { FormikErrors } from 'formik'; | ||
|
||
import { HIGH_FEE_AMOUNT_STX } from '@leather-wallet/constants'; | ||
import { isEmpty } from '@leather-wallet/utils'; | ||
|
||
import type { HasChildren } from '@app/common/has-children'; | ||
|
||
interface StacksHighFeeWarningContext { | ||
showHighFeeWarningDialog: boolean; | ||
setShowHighFeeWarningDialog(val: boolean): void; | ||
hasBypassedFeeWarning: boolean; | ||
setHasBypassedFeeWarning(val: boolean): void; | ||
isHighFeeWithNoFormErrors(errors: FormikErrors<unknown>, fee: number | string): boolean; | ||
} | ||
|
||
const stacksHighFeeWarningContext = createContext<StacksHighFeeWarningContext | null>(null); | ||
|
||
export function useStacksHighFeeWarningContext() { | ||
const ctx = useContext(stacksHighFeeWarningContext); | ||
if (!ctx) throw new Error(`stacksCommonSendFormContext must be used within a context`); | ||
return ctx; | ||
} | ||
|
||
const StacksHighFeeWarningProvider = stacksHighFeeWarningContext.Provider; | ||
|
||
export function StacksHighFeeWarningContainer({ children }: HasChildren) { | ||
const [showHighFeeWarningDialog, setShowHighFeeWarningDialog] = useState(false); | ||
const [hasBypassedFeeWarning, setHasBypassedFeeWarning] = useState(false); | ||
|
||
function isHighFeeWithNoFormErrors(errors: FormikErrors<unknown>, fee: number | string) { | ||
if (hasBypassedFeeWarning) return false; | ||
return isEmpty(errors) && new BigNumber(fee).isGreaterThan(HIGH_FEE_AMOUNT_STX); | ||
} | ||
|
||
return ( | ||
<StacksHighFeeWarningProvider | ||
value={{ | ||
showHighFeeWarningDialog, | ||
setShowHighFeeWarningDialog, | ||
hasBypassedFeeWarning, | ||
setHasBypassedFeeWarning, | ||
isHighFeeWithNoFormErrors, | ||
}} | ||
> | ||
{children} | ||
</StacksHighFeeWarningProvider> | ||
); | ||
} |
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
23 changes: 11 additions & 12 deletions
23
src/app/features/stacks-transaction-request/submit-action.tsx
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.