Skip to content

Commit

Permalink
fix: PP for cards did not display correctly everywhere (#1882)
Browse files Browse the repository at this point in the history
* fix PP for cards display

* Update helpers.ts

* Update WalletAddressesTable.tsx
  • Loading branch information
Tymmmy authored Jan 23, 2025
1 parent 1da7c0f commit 47dfb87
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
14 changes: 8 additions & 6 deletions packages/wallet/frontend/src/components/WalletAddressesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
} from '@/ui/Tooltip'
import { copyToClipboard } from '@/ui/CopyButton'
import { createContext, useContext, useEffect, useState } from 'react'
import {
replaceCardWalletAddressDomain,
replaceWalletAddressProtocol
} from '@/utils/helpers'

interface WalletAddressesTableProps {
account: Account
Expand Down Expand Up @@ -101,12 +105,10 @@ export const CopyWalletAddress = () => {
const { walletAddress } = useContext(WalletAddressRowContext)
const [isCopied, setIsCopied] = useState(false)

let pointer = walletAddress.url

if (walletAddress.isCard) {
const url = new URL(walletAddress.url.replace('$', 'https://'))
pointer = `$ilp.dev${url.pathname}`
}
const pointer = replaceCardWalletAddressDomain(
replaceWalletAddressProtocol(walletAddress.url),
walletAddress.isCard
)

useEffect(() => {
setTimeout(() => {
Expand Down
11 changes: 9 additions & 2 deletions packages/wallet/frontend/src/pages/account/[accountId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { walletAddressService } from '@/lib/api/walletAddress'
import { useOnboardingContext } from '@/lib/context/onboarding'
import { useDialog } from '@/lib/hooks/useDialog'
import { NextPageWithLayout } from '@/lib/types/app'
import { formatAmount, replaceWalletAddressProtocol } from '@/utils/helpers'
import {
formatAmount,
replaceCardWalletAddressDomain,
replaceWalletAddressProtocol
} from '@/utils/helpers'
import type {
GetServerSideProps,
InferGetServerSidePropsType
Expand Down Expand Up @@ -183,7 +187,10 @@ export const getServerSideProps: GetServerSideProps<{
}
}
walletAddressesResponse.result.map((pp) => {
pp.url = replaceWalletAddressProtocol(pp.url)
pp.url = replaceCardWalletAddressDomain(
replaceWalletAddressProtocol(pp.url),
pp.isCard
)
})

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/frontend/src/pages/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SuccessDialog } from '@/components/dialogs/SuccessDialog'
import {
formatAmount,
getObjectKeys,
replaceCardWalletAddressDomain,
replaceWalletAddressProtocol
} from '@/utils/helpers'
import { Select, type SelectOption } from '@/ui/forms/Select'
Expand Down Expand Up @@ -107,7 +108,7 @@ const RequestPage: NextPageWithLayout<RequestProps> = ({ accounts }) => {

const walletAddresses = walletAddressesResponse.result.map(
(walletAddress) => ({
label: `${walletAddress.publicName} (${replaceWalletAddressProtocol(walletAddress.url)})`,
label: `${walletAddress.publicName} (${replaceCardWalletAddressDomain(replaceWalletAddressProtocol(walletAddress.url), walletAddress.isCard)})`,
value: walletAddress.id,
url: walletAddress.url
})
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/frontend/src/pages/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SuccessDialog } from '@/components/dialogs/SuccessDialog'
import {
formatAmount,
getObjectKeys,
replaceCardWalletAddressDomain,
replaceWalletAddressProtocol
} from '@/utils/helpers'
import { useDialog } from '@/lib/hooks/useDialog'
Expand Down Expand Up @@ -117,7 +118,7 @@ const SendPage: NextPageWithLayout<SendProps> = ({ accounts }) => {

const walletAddresses = walletAddressesResponse.result.map(
(walletAddress) => ({
label: `${walletAddress.publicName} (${replaceWalletAddressProtocol(walletAddress.url)})`,
label: `${walletAddress.publicName} (${replaceCardWalletAddressDomain(replaceWalletAddressProtocol(walletAddress.url), walletAddress.isCard)})`,
value: walletAddress.id
})
)
Expand Down
11 changes: 9 additions & 2 deletions packages/wallet/frontend/src/pages/settings/developer-keys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { DeveloperKeys } from '@/components/settings/DeveloperKeys'
import { SettingsTabs } from '@/components/SettingsTabs'
import { Account, accountService } from '@/lib/api/account'
import { NextPageWithLayout } from '@/lib/types/app'
import { formatDate, replaceWalletAddressProtocol } from '@/utils/helpers'
import {
formatDate,
replaceCardWalletAddressDomain,
replaceWalletAddressProtocol
} from '@/utils/helpers'
import { GetServerSideProps, InferGetServerSidePropsType } from 'next/types'

type DeveloperKeysPageProps = InferGetServerSidePropsType<
Expand Down Expand Up @@ -44,7 +48,10 @@ export const getServerSideProps: GetServerSideProps<{
...account,
walletAddresses: account.walletAddresses.map((pp) => ({
...pp,
url: replaceWalletAddressProtocol(pp.url),
url: replaceCardWalletAddressDomain(
replaceWalletAddressProtocol(pp.url),
pp.isCard
),
keys: pp.keys?.map((key) => ({
...key,
id: key.id,
Expand Down
12 changes: 12 additions & 0 deletions packages/wallet/frontend/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ export const replaceWalletAddressProtocol = (
: paymentPointer
}

export const replaceCardWalletAddressDomain = (
paymentPointer: string,
isCard?: boolean
): string => {
if (isCard) {
const url = new URL(paymentPointer.replace('$', 'https://'))
return `$ilp.dev${url.pathname}`
} else {
return paymentPointer
}
}

export function ab2str(buf: ArrayBuffer) {
//@ts-expect-error: We know
return String.fromCharCode.apply(null, new Uint8Array(buf))
Expand Down

0 comments on commit 47dfb87

Please sign in to comment.