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: Ramp #1747

Closed
wants to merge 58 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fa0dcbc
feat: add ramp routes
UrbanWill Dec 10, 2024
815adea
feat: initial BuyForm setup
UrbanWill Dec 11, 2024
6a0a845
feat: added NumberInputWithDropdown component
UrbanWill Dec 11, 2024
ddbd15f
feat: getRampCurrencies, add ramp base path to env
UrbanWill Dec 12, 2024
c2d827d
feat: consume useGetRampCurrencies, update form
UrbanWill Dec 12, 2024
931e0f5
feat: added useGetRampAssetsByCurrency, updated buy form
UrbanWill Dec 12, 2024
f55969a
feat: debounced amount inputs to fetch up to date quotes
UrbanWill Dec 13, 2024
726b443
feat: update token/fiat based on form interaction
UrbanWill Dec 15, 2024
77ca542
feat: select account UI
UrbanWill Dec 15, 2024
749ed41
chore: added RAMP base path, path and api to env vars
UrbanWill Dec 15, 2024
e17b82f
feat: create url params and navigate on submit
UrbanWill Dec 15, 2024
f86ca1d
feat: format token plank before external navigation
UrbanWill Dec 15, 2024
09d23cf
feat: move ramp routes to Portfolio routes and layout
UrbanWill Dec 15, 2024
6de5d8b
feat: added missing UI for NumberInputWithDropDown
UrbanWill Dec 16, 2024
24b42c0
feat: added RampAccountOption
UrbanWill Dec 16, 2024
949dcea
feat: off ramp form
UrbanWill Dec 16, 2024
774e91e
feat: offramp assets hook
UrbanWill Dec 16, 2024
a74fb3a
feat: added ramp to popup routes
UrbanWill Dec 18, 2024
ca0333c
feat: added ramp ui to popup
UrbanWill Dec 18, 2024
5cf6879
fix: dropdown overflow on popup view
UrbanWill Dec 18, 2024
7add807
chore: pulled dev and solved conflicts
UrbanWill Dec 18, 2024
04994fb
fix: selected token should match chain
UrbanWill Dec 18, 2024
57f9720
feat: fetch ramp quote based on fiat or token amount
UrbanWill Dec 30, 2024
780faa1
feat: bi-directional onramp quote
UrbanWill Dec 31, 2024
dcb1737
feat: bi-directional offramp quote
UrbanWill Dec 31, 2024
cb646b4
fix: handle unsupported tokens when switching between buy/sell forms
UrbanWill Jan 1, 2025
16873eb
feat: searchable Dropdown
UrbanWill Jan 2, 2025
9dcf4a3
feat: step decimals, throw error if bad quote, cleanup
UrbanWill Jan 2, 2025
fe3fa2d
fix: searchInput import
UrbanWill Jan 2, 2025
6002ac3
feat: select button placeholder
UrbanWill Jan 2, 2025
a4331ba
feat: added Ramp url to mobile nav
UrbanWill Jan 2, 2025
01022e3
feat: added fiat currency info, logo and name
UrbanWill Jan 3, 2025
9f1b7e5
Merge branch 'feat/ramp' of github.com:TalismanSociety/talisman into …
UrbanWill Jan 3, 2025
f6107f8
chore: added SearchInput to components package
UrbanWill Jan 3, 2025
0380561
chore: moved SearchInput from components to talisman-ui package, upda…
UrbanWill Jan 3, 2025
1b55a8d
feat: add hostAppName and default flow to ramp url
UrbanWill Jan 3, 2025
456aafa
feat: cross reference supported tokens with chain data
UrbanWill Jan 4, 2025
e942ec2
feat: convert address by chain, display asset chain name
UrbanWill Jan 4, 2025
8415d45
feat: support evm tokens, activate network/token to store, perf impro…
UrbanWill Jan 5, 2025
da05268
feat: added evm token ids
UrbanWill Jan 6, 2025
89c288a
fix: minor form input UI fixes
UrbanWill Jan 6, 2025
415c7a9
feat: added toggle buy switch to expanded view
UrbanWill Jan 6, 2025
498f6da
chore: display DashboardAccountsSidebar on Ramp routes
UrbanWill Jan 6, 2025
5f99f7c
chore: hide navigation chevron on expanded view
UrbanWill Jan 6, 2025
792d95b
chore: remove old buy components
UrbanWill Jan 6, 2025
12e9ff4
feat: updated fetch remote config, mocked values, log token/chain not…
UrbanWill Jan 6, 2025
9bc43e9
chore: pulled dev and solved conflicts
UrbanWill Jan 6, 2025
dc24bd6
fix: circular dependency import
UrbanWill Jan 7, 2025
c7bd600
fix: labels, styles & placeholders
UrbanWill Jan 7, 2025
99c8a6e
fix: network specific account icon
UrbanWill Jan 7, 2025
6fa28d0
feat: min fiat amount error message
UrbanWill Jan 7, 2025
bd6cc60
chore: center cols and buy btn
UrbanWill Jan 7, 2025
6fafa4b
fix: "popup view" on exapnded clipping
UrbanWill Jan 7, 2025
ff157f7
chore: update ramp routes
UrbanWill Jan 7, 2025
9edc6a1
chore: moved ramp env vars to remote config
UrbanWill Jan 8, 2025
7ca0dbe
feat: sort tokens/accounts depending on each others chain type,
UrbanWill Jan 8, 2025
9ee83ae
feat: add account prompt
UrbanWill Jan 8, 2025
f0e5fe6
fix: added shouldRevalidate to onClea
UrbanWill Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added useGetRampAssetsByCurrency, updated buy form
UrbanWill committed Dec 12, 2024
commit 931e0f52d9e4ddc99a9d1e5507d650e85a700e76
56 changes: 47 additions & 9 deletions apps/extension/src/ui/domains/Ramp/RampBuyForm.tsx
Original file line number Diff line number Diff line change
@@ -6,30 +6,32 @@ import * as yup from "yup"

import { useSelectedCurrency } from "@ui/state"

import { RampCurrency } from "./hooks/types"
import { useGetRampAssetsByCurrency } from "./hooks/useGetRampAssetsByCurrency"
import { useGetRampCurrencies } from "./hooks/useGetRampCurrencies"
import { NumberInputWithDropDown } from "./NumberInputWithDropDown"
import { RampAsset, RampCurrency } from "./types"
import { truncateToSignificantDigits } from "./utils"

type FormData = {
address: string
fiatAmount: number
tokenId: string
fiatCurrency: string
tokenId: string
chain: string
tokenAmount: number
}

const schema = yup.object({
address: yup.string().required(" "),
fiatAmount: yup.number().required(" ").min(0),
tokenAmount: yup.number().required(" ").min(0),
tokenId: yup.string().required(" "),
fiatCurrency: yup.string().required(" "),
chain: yup.string().required(" "),
})

export const RampBuyForm = () => {
const currency = useSelectedCurrency()
const { data: rampCurrencies } = useGetRampCurrencies()

const onrampCurrencies = rampCurrencies?.filter((curr) => curr.onrampAvailable) ?? []

const {
register,
handleSubmit,
@@ -40,35 +42,55 @@ export const RampBuyForm = () => {
mode: "all",
defaultValues: {
fiatCurrency: currency.toUpperCase(),
chain: "DOT",
tokenId: "DOT",
},
resolver: yupResolver(schema),
})
const [fiatCurrency, tokenId, chain] = watch(["fiatCurrency", "tokenId", "chain"])

const { data: rampCurrencies } = useGetRampCurrencies()
const { data: rampCurrencyWithAssets } = useGetRampAssetsByCurrency({
currencyCode: fiatCurrency,
})

const onrampCurrencies = rampCurrencies?.filter((curr) => curr.onrampAvailable) ?? []
const tokenRateByCurrency = rampCurrencyWithAssets?.assets.find(
(asset) => asset.symbol === tokenId && asset.chain === chain,
)?.price[fiatCurrency]

const [fiatCurrency] = watch(["fiatCurrency"])
// const submit = (data: FormData) => console.log({ data })
const submit = (data: FormData) => data

const handleFiatCurrencyChange = (fiatCurrency: RampCurrency | null) => {
setValue("fiatCurrency", fiatCurrency?.fiatCurrency ?? "")
}

const handleTokenChange = (rampAsset: RampAsset | null) => {
setValue("tokenId", rampAsset?.symbol ?? "")
setValue("chain", rampAsset?.chain ?? "")
}

const selectedFiatCurrency = onrampCurrencies.find((curr) => curr.fiatCurrency === fiatCurrency)
const selectedToken = rampCurrencyWithAssets?.assets.find((asset) => asset.symbol === tokenId)

const renderFiatCurrencyItem: DropdownOptionRender<RampCurrency> = (item) => {
return <div className="flex flex-col justify-center">{item.fiatCurrency}</div>
}
const renderTokenItem: DropdownOptionRender<RampAsset> = (item) => {
return <div className="flex flex-col justify-center">{item.symbol}</div>
}

const { t } = useTranslation()
return (
<div className="text-body-secondary h-[30rem] w-[32rem] xl:w-[64rem]">
<form onSubmit={handleSubmit(submit)}>
<div className="border-grey-750 space-y-8 rounded-2xl border-[1px] p-6">
<div className="border-grey-750 space-y-6 rounded-2xl border-[1px] p-6">
<div className="flex gap-4">
<div className="font-bold text-white">{t("Step1")}</div>
<div>{t("Select Asset")}</div>
</div>
<div className="text-xs">{t("You Pay")}</div>

<NumberInputWithDropDown
inputFieldProps={register("fiatAmount")}
inputFieldLabel={fiatCurrency}
@@ -81,6 +103,22 @@ export const RampBuyForm = () => {
renderItem={renderFiatCurrencyItem}
onChange={handleFiatCurrencyChange}
/>
<div className="flex justify-between">
<div className="text-xs">{t("You're receiving (estimate)")}</div>
<div className="text-xs">{`1 ${tokenId} ≈ ${truncateToSignificantDigits(tokenRateByCurrency ?? 0)} ${fiatCurrency}`}</div>
</div>
<NumberInputWithDropDown
inputFieldProps={register("tokenAmount")}
inputFieldLabel={"$"}
inputType="string"
inputPlaceholder="0"
propertyKey="address"
placeholder={t("Select token")}
items={rampCurrencyWithAssets?.assets ?? []}
value={selectedToken}
renderItem={renderTokenItem}
onChange={handleTokenChange}
/>
</div>
<Button type="submit" primary disabled={!isValid}>
{t("Continue")}
6 changes: 0 additions & 6 deletions apps/extension/src/ui/domains/Ramp/hooks/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { keepPreviousData, useQuery } from "@tanstack/react-query"
import { RAMP_BASE_PATH } from "extension-shared"

import { RampCurrencyWithAssets } from "../types"

// note: currencyCode must be upper case
const fetchRampAssetsByCurrency = async (currencyCode: string): Promise<RampCurrencyWithAssets> => {
try {
return await (
await fetch(`${RAMP_BASE_PATH}/assets?currencyCode=${currencyCode.toUpperCase()}`, {
method: "GET",
})
).json()
} catch (cause) {
throw new Error("Failed to fetch Ramp assets", { cause })
}
}

export const useGetRampAssetsByCurrency = ({ currencyCode }: { currencyCode: string }) => {
return useQuery({
queryKey: ["useGetRampAssets", currencyCode],
queryFn: () => fetchRampAssetsByCurrency(currencyCode),
staleTime: 1000 * 60,
placeholderData: keepPreviousData,
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from "@tanstack/react-query"
import { RAMP_BASE_PATH } from "extension-shared"

import { RampCurrency } from "./types"
import { RampCurrency } from "../types"

const fetchRampCurrencies = async (): Promise<RampCurrency[]> => {
try {
@@ -19,6 +19,6 @@ export const useGetRampCurrencies = () => {
return useQuery({
queryKey: ["useGetRampCurrencies"],
queryFn: () => fetchRampCurrencies(),
staleTime: 1000 * 60,
staleTime: 1000 * 60 * 5,
})
}
36 changes: 36 additions & 0 deletions apps/extension/src/ui/domains/Ramp/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export type RampCurrency = {
fiatCurrency: string
name: string
onrampAvailable: boolean
offrampAvailable: boolean
}

type AssetPrice = Record<string, number>

export type RampAsset = {
address: string
symbol: string
chain: string
name: string
decimals: number
type: string
enabled: boolean
logoUrl: string
hidden: boolean
networkFee: number
price: AssetPrice
currencyCode: string
minPurchaseAmount: number
maxPurchaseAmount: number
minPurchaseCryptoAmount: string
}

export type RampCurrencyWithAssets = {
currencyCode: string
minPurchaseAmount: number
maxPurchaseAmount: number
minFeeAmount: number
minFeePercent: number
maxFeePercent: number
assets: RampAsset[]
}
12 changes: 12 additions & 0 deletions apps/extension/src/ui/domains/Ramp/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const truncateToSignificantDigits = (input: number): number => {
const str = input.toString()
if (!str.includes(".")) return input

const [integerPart, decimalPart] = str.split(".")

const firstNonZeroIndex = decimalPart.split("").findIndex((digit) => digit !== "0")

const truncatedDecimal = decimalPart.slice(0, firstNonZeroIndex + 2)

return parseFloat(`${integerPart}.${truncatedDecimal}`)
}
2 changes: 1 addition & 1 deletion packages/talisman-ui/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ export const Dropdown = <T extends Record<string, unknown>>({
<Listbox.Options>
{items.map((item, i, arr) => (
<Listbox.Option
key={item[propertyKey] as string | number}
key={`${item[propertyKey]}-${i}` as string | number}
value={item}
className={classNames(
"bg-grey-800 hover:bg-grey-750 hover:text-grey-300 w-full max-w-full cursor-pointer overflow-hidden p-8",