Skip to content

Commit d10ef60

Browse files
committed
chore: fix review comments
1 parent 4f2bfea commit d10ef60

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

packages/snap/src/core/handlers/onNameLookup/onNameLookup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { type OnNameLookupHandler } from '@metamask/snaps-sdk';
22
import { assert } from '@metamask/superstruct';
33

44
import { nameResolutionService } from '../../../snapContext';
5-
import { SolanaNameLookupRequesstStruct } from './structs';
5+
import { SolanaNameLookupRequestStruct } from './structs';
66

77
const SOLANA_NAME_SERVICE_PROTOCOL = 'Solana Name Service';
88

99
export const onNameLookupHandler: OnNameLookupHandler = async (request) => {
10-
assert(request, SolanaNameLookupRequesstStruct);
10+
assert(request, SolanaNameLookupRequestStruct);
1111

1212
const { chainId, domain, address } = request;
1313

packages/snap/src/core/handlers/onNameLookup/structs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { object, optional, string } from '@metamask/superstruct';
22

33
import { NetworkStruct } from '../../validation/structs';
44

5-
export const SolanaNameLookupRequesstStruct = object({
5+
export const SolanaNameLookupRequestStruct = object({
66
chainId: NetworkStruct,
77
domain: optional(string()),
88
address: optional(string()),

packages/snap/src/features/send/utils/isSolanaDomain.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ describe('isSolanaDomain', () => {
5050
expect(isSolanaDomain('')).toBe(false);
5151
});
5252

53-
it('returns true for string with only .sol', () => {
54-
expect(isSolanaDomain('.sol')).toBe(true);
53+
it('returns false for string with only .sol', () => {
54+
expect(isSolanaDomain('.sol')).toBe(false);
5555
});
5656

5757
it('returns false for string ending with .SOL (uppercase)', () => {

packages/snap/src/features/send/utils/isSolanaDomain.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
* Checks if a domain is a Solana domain (.sol).
33
*
44
* @param domain - The domain to check.
5-
* @returns `true` if the domain ends with `.sol`, `false` otherwise. Returns `false` if the domain is `null`.
5+
* @returns `true` if the domain is a valid domain ending with `.sol`, `false` otherwise. Returns `false` if the domain is `null`.
66
*/
77
export function isSolanaDomain(domain: string | null): boolean {
8-
return domain?.endsWith('.sol') ?? false;
8+
if (!domain) {
9+
return false;
10+
}
11+
12+
// Regex to match valid domain ending with .sol
13+
// Allows letters, numbers, hyphens, but not starting/ending with hyphen
14+
// Must have at least one character before .sol
15+
// Supports subdomains (e.g., sub.example.sol)
16+
const solanaDomainRegex =
17+
/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.sol$/u;
18+
19+
return solanaDomainRegex.test(domain);
920
}

0 commit comments

Comments
 (0)