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

feat: support to show fiat amounts #427

Merged
merged 3 commits into from
Sep 21, 2023
Merged

Conversation

vojtechsimetka
Copy link
Contributor

Resolves #128

What is missing but will not be part of this PR:

  • fetching the fiat (DAI) amounts from blockchain - issues with uniswap SDK

Design reasoning:

When implementing, i played with several ideas how to best expose the rates to the app. The minimum that I need is:

refreshing: boolean // info whether I am currently fetching the rates
error?: Error
checkedAt?: number // last time checked to avoid spamming endpoints
rates?: {
    DAI: number
    ...
}

With this we can detect if rates have been checked (checkedAt and rates or error are defined/populated).

1. [REJECTED] Making the rates part of Token interface in balanceStore

This was rejected, because token balances are updated in the waku adapter and it already has a lot of things to do, it did not feel like this is the right place to add more responsibility. I played with the TokenAmount looking like this:

interface TokenAmountWithRates {
    symbol: string
    amount: bigint
    decimals: number
    name: string
    image?: string | undefined
    address?: string | undefined
    exchangeRates: {
        DAI?: number
        EUR?: number
        ...
        refreshing: boolean
        error?: Error
        checkedAt?: number
    }
}

2. [IMPLEMENTED] Exchange store with rates for all app tokens

Instead I opted to implement extra store, where the rates are in Map<string, Rates>.

interface Rates {
    rates?: {
        DAI: number
        EUR: number
        ...
    }
    refreshing: boolean
    checkedAt?: number
    error?: Error
}

I considered writing a store function that fetches the appropriate rate, but that felt quite unnecessary and does not work in waku object where we are not trying to import the stores directly.

@vercel
Copy link

vercel bot commented Sep 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku-objects-playground ✅ Ready (Inspect) Visit Preview Sep 21, 2023 3:12pm

@vojtechsimetka vojtechsimetka merged commit 93617e6 into main Sep 21, 2023
2 checks passed
@vojtechsimetka vojtechsimetka deleted the feat/show-fiat-amounts branch September 21, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Payggy: implement pricing in fiat
2 participants