-
Notifications
You must be signed in to change notification settings - Fork 6
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
Show current position in Ledger Live dApp #302
Conversation
✅ Deploy Preview for acre-dapp-testnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
ab937c1
to
b34a2c7
Compare
b34a2c7
to
34ed19c
Compare
isLoadingPriceUSD: boolean | ||
usdPrice: number | ||
} | ||
|
||
const initialState: BtcState = { | ||
estimatedBtcBalance: 0n, | ||
sharesBalance: 0n, |
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.
I'm not convinced that this is the best place to keep it. sharesBalance
balance is actually stBTC
balance and from the developers perspective it could be misleading. I'm wondering if we shouldn't do something like we did in Threshold dashboard - create slice for tokens see:
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.
As we agreed, let's do it in a separate task: #315, because of touching some not-related parts of the code.
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.
I also agree. I think we should also give this a higher priority to organize the redux structure.
dapp/src/store/middleware.ts
Outdated
@@ -1 +1,3 @@ | |||
export const middleware = {} | |||
export const middleware = { | |||
serializableCheck: false, |
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.
Why did we switch it off?
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.
Because without this we get an error in console, when fetching BTC price from coingecko:
useFetchBTCPriceUSD.ts:10 A non-serializable value was detected in the state, in the path: `btc.estimatedBtcBalance`. Value: 0n
Take a look at the reducer(s) handling this action type: btc/fetchBTCPriceUSD/fulfilled.
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.
That's weird because bigint
is a primitive type. Looks like it is a bug in redux-toolkit see https://redux-toolkit.js.org/api/serializabilityMiddleware#isplain. But I think we can override it.
import {
configureStore,
createSerializableStateInvariantMiddleware,
isPlain as reduxToolkitIsPlain,
} from "@reduxjs/toolkit"
import { middleware } from "./middleware"
import { reducer } from "./reducer"
const isPlain = (value: unknown) => {
const type = typeof value
return reduxToolkitIsPlain(value) || type === "bigint"
}
const serializableMiddleware = createSerializableStateInvariantMiddleware({
isSerializable: isPlain,
})
export const store = configureStore({
reducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware(middleware).concat(serializableMiddleware),
devTools: !import.meta.env.PROD,
})
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
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.
That's weird because
bigint
is a primitive type
Indeed, bigint
is non-seriazable
, and it's why we get this error:
A non-serializable value was detected in the state
.
Redux doc says:
/**
- The function to check if a value is considered serializable. This
- function is applied recursively to every value contained in the
- state. Defaults to
isPlain()
.
*/
isSerializable?: (value: any) => boolean
I'm not sure if overriding isPlain
function is a good idea, sounds like a workaround, and in the future, we will have to extend this function to all primitive types.
In my opinion, disabling serializableCheck
is more convenient and I don't see any risk in turning it off at this point.
If there is such a thing in the future, we might consider overriding isPlain
, what do you think?
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.
Note that including non-serializable data in the store will break things like redux devtools. For reference in the future, here is how we set this up in Taho, where we included remote devtools explicitly (vs having it built in via browser extension, since we were already inside an extension):
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.
Ah I thought, the bigint
is serializable but BigInt
is not but they are actually the same type sorry. I found this in the docs, maybe it will be helpful https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
73e337d
to
4d23992
Compare
dc4a62c
to
3c72154
Compare
c25377d
to
a26d97e
Compare
isLoadingPriceUSD: boolean | ||
usdPrice: number | ||
} | ||
|
||
const initialState: BtcState = { | ||
estimatedBtcBalance: 0n, | ||
sharesBalance: 0n, |
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.
I also agree. I think we should also give this a higher priority to organize the redux structure.
dapp/src/store/enhancers.ts
Outdated
|
||
export const enhancers = import.meta.env.DEV | ||
? { | ||
autoBatch: undefined, |
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.
Why do we need it?
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.
To meet the type of restriction: GetDefaultEnhancersOptions
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.
It seems that this parameter is optional. In that case, can we just skip it? I feel that this creates a bit of confusion.
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.
yes, I've checked this before, but we still get an error without it:
Argument of type '{ devToolsEnhancer: StoreEnhancer; } | { devToolsEnhancer?: undefined; }' is not assignable to parameter of type 'GetDefaultEnhancersOptions | undefined'.
Type '{ devToolsEnhancer: StoreEnhancer; }' has no properties in common with type 'GetDefaultEnhancersOptions'.
dapp/package.json
Outdated
@@ -21,6 +21,7 @@ | |||
"@emotion/styled": "^11.11.0", | |||
"@ledgerhq/wallet-api-client": "^1.5.0", | |||
"@ledgerhq/wallet-api-client-react": "^1.3.0", | |||
"@redux-devtools/extension": "^3.3.0", |
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.
To clarify. Why do we need this package?
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.
@redux-devtools/extension
is required to configure devToolsEnhancer
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.
But why do we need to configure devToolsEnhancer
? I wonder why we didn't configure it in devTools
? 🤔 I would like to understand this better because I remember that in Taho dApp did not install an external package for this.
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.
It was commented on here: #302 (comment)
But of course, there is no problem with doing the same in a different way that you proposed and was used in the Taho dApp.
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.
I was just curious why you used an external library.
d75f77f
to
99ff8d9
Compare
b11b646
to
cf86aa5
Compare
> Closes: #264 --- ### Show Liquid Staking token position popover --- ### _What was done:_ - created Chakra-UI Popover-based component to show Liquid Staking token position. - added resize event listener to update popover width & height when the `PositionDetails` card size changes (e.g. when collapsing the left sidebar in Ledger Nano). - Removed blue outline when focused(accessibility property) from the chakra popover. --- ### _Preview:_ <img width="475" alt="Screenshot 2024-03-11 at 16 08 54" src="https://github.com/thesis/acre/assets/28560653/111f34c8-e697-48c2-a050-3d09c812c2ec"> --- ### _Additional info:_ - the amount of stBTC will be updated when #302 is merged
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.
I left only minor comments/questions.
I noticed that PR has been merged earlier. The description includes the following information:
Additional info:
the amount of stBTC will be updated when #302 is merged
Let's not miss it and make sure to correctly display the amount of stBTC. We can do it in this PR or the next but let's not lose it.
Yep, I added shares balance to |
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.
Overall, it looks good. Let's fix the build and merge it. 🚢
3f0b3db
to
768bbeb
Compare
768bbeb
to
d99c98f
Compare
Show current position in Ledger Live dApp
What was done:
serializableCheck
to redux middleware (https://redux-toolkit.js.org/api/serializabilityMiddleware)Additional info: