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

Show current position in Ledger Live dApp #302

Merged
merged 13 commits into from
Apr 9, 2024
Merged

Conversation

ioay
Copy link
Contributor

@ioay ioay commented Mar 5, 2024

Closes: #111


Show current position in Ledger Live dApp


What was done:


Additional info:

  • Conversion to USD is out of the scope of this task.

@ioay ioay self-assigned this Mar 5, 2024
Copy link

netlify bot commented Mar 5, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 6b291f1
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/661505ff54d3660008b89f1f
😎 Deploy Preview https://deploy-preview-302--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ioay ioay force-pushed the dapp_show_current_position branch 6 times, most recently from ab937c1 to b34a2c7 Compare March 8, 2024 13:42
@ioay ioay marked this pull request as ready for review March 8, 2024 13:52
@ioay ioay marked this pull request as draft March 8, 2024 14:19
@ioay ioay marked this pull request as ready for review March 8, 2024 14:33
@ioay ioay force-pushed the dapp_show_current_position branch from b34a2c7 to 34ed19c Compare March 11, 2024 14:33
isLoadingPriceUSD: boolean
usdPrice: number
}

const initialState: BtcState = {
estimatedBtcBalance: 0n,
sharesBalance: 0n,
Copy link
Contributor

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:

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -1 +1,3 @@
export const middleware = {}
export const middleware = {
serializableCheck: false,
Copy link
Contributor

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?

Copy link
Contributor Author

@ioay ioay Mar 14, 2024

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.

#302 (comment)

Copy link
Contributor

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

Copy link
Contributor Author

@ioay ioay Mar 19, 2024

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?

Copy link
Collaborator

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):

https://github.com/tahowallet/extension/blob/4a93eba515c6a63fd5c4aa4d44a05775355b5792/background/main.ts#L204-L220

https://github.com/tahowallet/extension/blob/4a93eba515c6a63fd5c4aa4d44a05775355b5792/background/main.ts#L246-L289

Copy link
Contributor

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

@ioay ioay requested a review from r-czajkowski March 14, 2024 16:56
@ioay ioay force-pushed the dapp_show_current_position branch from 73e337d to 4d23992 Compare March 14, 2024 17:09
@ioay ioay force-pushed the dapp_show_current_position branch from dc4a62c to 3c72154 Compare March 21, 2024 21:25
@ioay ioay force-pushed the dapp_show_current_position branch from c25377d to a26d97e Compare March 21, 2024 22:24
isLoadingPriceUSD: boolean
usdPrice: number
}

const initialState: BtcState = {
estimatedBtcBalance: 0n,
sharesBalance: 0n,
Copy link
Contributor

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.


export const enhancers = import.meta.env.DEV
? {
autoBatch: undefined,
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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'.

@@ -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",
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@ioay ioay Apr 3, 2024

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.

cf86aa5

Copy link
Contributor

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.

@ioay ioay requested a review from kkosiorowska March 22, 2024 14:30
@ioay ioay force-pushed the dapp_show_current_position branch from d75f77f to 99ff8d9 Compare April 3, 2024 22:06
@ioay ioay force-pushed the dapp_show_current_position branch from b11b646 to cf86aa5 Compare April 3, 2024 22:59
@nkuba nkuba added the 🎨 dApp dApp label Apr 4, 2024
ioay added a commit that referenced this pull request Apr 4, 2024
> 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
Copy link
Contributor

@kkosiorowska kkosiorowska left a 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.

@ioay
Copy link
Contributor Author

ioay commented Apr 4, 2024

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 LiquidStakingTokenPopover in this PR : d71a13b

@ioay ioay requested a review from kkosiorowska April 4, 2024 21:18
Copy link
Contributor

@kkosiorowska kkosiorowska left a 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. 🚢

@ioay ioay force-pushed the dapp_show_current_position branch 2 times, most recently from 3f0b3db to 768bbeb Compare April 5, 2024 11:25
@ioay ioay force-pushed the dapp_show_current_position branch from 768bbeb to d99c98f Compare April 5, 2024 11:27
@ioay ioay requested a review from kkosiorowska April 5, 2024 11:29
@ioay ioay enabled auto-merge April 5, 2024 11:39
@ioay ioay merged commit e26e660 into main Apr 9, 2024
24 checks passed
@ioay ioay deleted the dapp_show_current_position branch April 9, 2024 09:13
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.

Show current position in Ledger Live dApp
5 participants