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(popup): allow short form for wallet addresses in popup #421

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions src/popup/components/ConnectWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { debounceSync, getWalletInformation } from '@/shared/helpers'
import {
charIsNumber,
formatNumber,
getCurrencySymbol
getCurrencySymbol,
toWalletAddressUrl
} from '@/popup/lib/utils'
import { useForm } from 'react-hook-form'

Expand Down Expand Up @@ -52,7 +53,7 @@ export const ConnectWalletForm = ({ publicKey }: ConnectWalletFormProps) => {
clearErrors('walletAddressUrl')
if (!walletAddressUrl) return
try {
const url = new URL(walletAddressUrl)
const url = new URL(toWalletAddressUrl(walletAddressUrl))
const walletAddress = await getWalletInformation(url.toString())
setCurrencySymbol({
symbol: getCurrencySymbol(walletAddress.assetCode),
Expand All @@ -61,7 +62,7 @@ export const ConnectWalletForm = ({ publicKey }: ConnectWalletFormProps) => {
} catch (e) {
setError('walletAddressUrl', {
type: 'validate',
message: 'Invalid wallet address URL.'
message: 'Invalid wallet address.'
})
}
},
Expand Down Expand Up @@ -107,7 +108,10 @@ export const ConnectWalletForm = ({ publicKey }: ConnectWalletFormProps) => {
return (
<form
onSubmit={handleSubmit(async (data) => {
const response = await connectWallet(data)
const response = await connectWallet({
...data,
walletAddressUrl: toWalletAddressUrl(data.walletAddressUrl)
})
if (!response.success) {
setError('walletAddressUrl', {
type: 'validate',
Expand Down Expand Up @@ -137,8 +141,8 @@ export const ConnectWalletForm = ({ publicKey }: ConnectWalletFormProps) => {
<Code className="text-xs" value={publicKey} />
</div>
<Input
type="url"
label="Wallet address"
type="text"
label="Wallet address or payment pointer"
disabled={connected}
placeholder="https://ilp.rafiki.money/johndoe"
errorMessage={errors.walletAddressUrl?.message}
Expand Down
10 changes: 9 additions & 1 deletion src/popup/lib/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatNumber } from './utils'
import { formatNumber, toWalletAddressUrl } from './utils'

describe('formatNumber', () => {
it('should display right format for integers', () => {
Expand Down Expand Up @@ -43,3 +43,11 @@ describe('formatNumber', () => {
expect(formatNumber(0.000100009, 9)).toEqual('0.000100009')
})
})

describe('toWalletAddressUrl', () => {
it('converts from short form to long form', () => {
expect(toWalletAddressUrl('$wallet.com/bob')).toEqual(
'https://wallet.com/bob'
)
})
})
4 changes: 4 additions & 0 deletions src/popup/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@
} else return value.toExponential()
}
}

export function toWalletAddressUrl(s: string): string {
return s.startsWith('$') ? s.replace('$', 'https://') : s
Dismissed Show dismissed Hide dismissed
}
Loading