Skip to content
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

Safemath pt 2 #5778

Merged
merged 3 commits into from
May 29, 2024
Merged

Safemath pt 2 #5778

merged 3 commits into from
May 29, 2024

Conversation

brunobar79
Copy link
Member

@brunobar79 brunobar79 commented May 28, 2024

Fixes APP-####

What changed (plus any additional context for devs)

Adds more methods:

  • log10
  • toFixed
  • round
  • floor
  • ceil

Accepts parameters of type number or string

Screen recordings / screenshots

Screenshot 2024-05-28 at 11 56 13 AM

What to test

const scaledBigInt1 = scaleUpWorklet(bigInt1, decimalPlaces1);
const scaledBigInt2 = scaleUpWorklet(bigInt2, decimalPlaces2);
const result = (scaledBigInt1 * scaledBigInt2) / BigInt(10) ** BigInt(20);
return formatResultWorklet(result);
}

// Divide function
export function divWorklet(num1: string, num2: string): string {
export function divWorklet(num1: string | number, num2: string | number): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to make it "easy" to keep numbers in the codebase?
like we can make the user use string by not accepting number in the api or at least indicate something is up by making his code ugly having to parse before lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just getting started to replace the unsafe Number usages inside the worklets and I'm not sure what I'm gonna find out so I'll keep it flexible like this to move faster but in the end I'd like to find all the occurrences and make it more stricter if possible

@brunobar79 brunobar79 merged commit 22def71 into develop May 29, 2024
6 checks passed
@brunobar79 brunobar79 deleted the @bruno/safemath-pt-2 branch May 29, 2024 17:08
greg-schrammel pushed a commit that referenced this pull request May 29, 2024
* add more fns

* accept string or number

* update errors
greg-schrammel added a commit that referenced this pull request Jun 14, 2024
* wip

* fix gesture button states

* Safemath pt 2 (#5778)

* add more fns

* accept string or number

* update errors

* fix dynamic island overlap on recieve modal (#5672)

* .

* oop

* oop

* okay ty ben

* change background opacity to 1

* .

* oop

* .

* Gas optimizations (#5779)

* perf

* ✨

* useWhyDidYouUpdate

* EstimatedSwapGasFee

* keepPreviousData

* AnimatedText

* isSameAddress

* fix other networks section (#5784)

* Swaps: fix favorite button press (#5782)

* fix

* android fix

* todo

* remove console logs

* Insufficient Funds

* remove todo

* move cache getter closer to fetcher implentation

* fix

* :)

* 🍕

* or equal 🤌

* remove unused isSameAddress util

* just reordering declarations

* error i18n

* useGasSharedValues

* remove estimating

* fix label flickering

* fix review panel not prompting

* Revert "Lint on pre-commit (#5836)"

This reverts commit d56ed46.

* fix a bunch of shit

---------

Co-authored-by: Matthew Wall <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
Co-authored-by: brdy <[email protected]>
Co-authored-by: Ben Goldberg <[email protected]>
brunobar79 added a commit that referenced this pull request Jun 21, 2024
* wip

* fix gesture button states

* Safemath pt 2 (#5778)

* add more fns

* accept string or number

* update errors

* fix dynamic island overlap on recieve modal (#5672)

* .

* oop

* oop

* okay ty ben

* change background opacity to 1

* .

* oop

* .

* Gas optimizations (#5779)

* perf

* ✨

* useWhyDidYouUpdate

* EstimatedSwapGasFee

* keepPreviousData

* AnimatedText

* isSameAddress

* fix other networks section (#5784)

* Swaps: fix favorite button press (#5782)

* fix

* android fix

* todo

* remove console logs

* Insufficient Funds

* remove todo

* move cache getter closer to fetcher implentation

* fix

* :)

* 🍕

* or equal 🤌

* remove unused isSameAddress util

* just reordering declarations

* error i18n

* useGasSharedValues

* remove estimating

* fix label flickering

* fix review panel not prompting

* Revert "Lint on pre-commit (#5836)"

This reverts commit d56ed46.

* fix a bunch of shit

* fix?

* opacity

* on review panel we should show fetching status and quote errors too

* remove error

* useUserNativeNetworkAsset

* less or equal

* Fixes for review button states (#5873)

* Fixes APP-1601: adds missing useThreshold for gas fee showing $0.00

* Tweak confirm button prop labels logic and ordering

* Prep work: remove reliance of asset balance display in valueBasedDecimalFormatter

* niceIncrementerFormatter returns asset balance if max swap

* Update formattedInputValue

Instead of using the niceIncrementFormatter for formatting slider-based
values:
for max: use the valueBasedDecimalFormatter on the input value which has
already been set to maxSwappableAmount
for everything else: add commas to the input value as it has already been
formatted using the niceIncrementFormatter

* Fixup: missed spot for previous hasEnoughFundsForGas revert

* fix formatting

---------

Co-authored-by: gregs <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
Co-authored-by: brdy <[email protected]>
Co-authored-by: Ben Goldberg <[email protected]>
Co-authored-by: Jin <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
jinchung added a commit that referenced this pull request Jun 22, 2024
#5881)

* wip

* fix gesture button states

* Safemath pt 2 (#5778)

* add more fns

* accept string or number

* update errors

* fix dynamic island overlap on recieve modal (#5672)

* .

* oop

* oop

* okay ty ben

* change background opacity to 1

* .

* oop

* .

* Gas optimizations (#5779)

* perf

* ✨

* useWhyDidYouUpdate

* EstimatedSwapGasFee

* keepPreviousData

* AnimatedText

* isSameAddress

* fix other networks section (#5784)

* Swaps: fix favorite button press (#5782)

* fix

* android fix

* todo

* remove console logs

* Insufficient Funds

* remove todo

* move cache getter closer to fetcher implentation

* fix

* :)

* 🍕

* or equal 🤌

* remove unused isSameAddress util

* just reordering declarations

* error i18n

* useGasSharedValues

* remove estimating

* fix label flickering

* fix review panel not prompting

* Revert "Lint on pre-commit (#5836)"

This reverts commit d56ed46.

* fix a bunch of shit

* fix?

* opacity

* on review panel we should show fetching status and quote errors too

* remove error

* useUserNativeNetworkAsset

* less or equal

* gas fee range

* fixes

* Fixes for review button states (#5873)

* Fixes APP-1601: adds missing useThreshold for gas fee showing $0.00

* Tweak confirm button prop labels logic and ordering

* Prep work: remove reliance of asset balance display in valueBasedDecimalFormatter

* niceIncrementerFormatter returns asset balance if max swap

* Update formattedInputValue

Instead of using the niceIncrementFormatter for formatting slider-based
values:
for max: use the valueBasedDecimalFormatter on the input value which has
already been set to maxSwappableAmount
for everything else: add commas to the input value as it has already been
formatted using the niceIncrementFormatter

* merge

* weird issues

* fixes

* fix out of sync issue

* update input amount + quote when maxSwappableAmount changes

* fix input formatting logic

* fix wei conversion

---------

Co-authored-by: gregs <[email protected]>
Co-authored-by: Matthew Wall <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
Co-authored-by: brdy <[email protected]>
Co-authored-by: Jin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants