diff --git a/packages/examples/packages/name-lookup/snap.manifest.json b/packages/examples/packages/name-lookup/snap.manifest.json index a9b37e9c18..3ee540f3e7 100644 --- a/packages/examples/packages/name-lookup/snap.manifest.json +++ b/packages/examples/packages/name-lookup/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "xk7O5itVsuV3Dfldq3rI3WgggHa3z7HX7e17jzheE8w=", + "shasum": "xFeB7CqtdR3GLUmfSmxzes32oUFEVzCbniKprMtx7vY=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/src/index.test.ts b/packages/examples/packages/name-lookup/src/index.test.ts index dbd671defc..fc58d00de7 100644 --- a/packages/examples/packages/name-lookup/src/index.test.ts +++ b/packages/examples/packages/name-lookup/src/index.test.ts @@ -3,7 +3,7 @@ import type { ChainId } from '@metamask/snaps-sdk'; import { onNameLookup } from '.'; -const DOMAIN_MOCK = 'test.domain'; +const DOMAIN_MOCK = 'fooBar'; const ADDRESS_MOCK = '0xc0ffee254729296a45a3885639AC7E10F9d54979'; const CHAIN_ID_MOCK = 'eip155:1' as ChainId; diff --git a/packages/examples/packages/name-lookup/src/index.ts b/packages/examples/packages/name-lookup/src/index.ts index fa91fd1d8b..61472dc1a1 100644 --- a/packages/examples/packages/name-lookup/src/index.ts +++ b/packages/examples/packages/name-lookup/src/index.ts @@ -21,12 +21,36 @@ export const onNameLookup: OnNameLookupHandler = async (request) => { } if (domain) { - const resolvedAddress = '0xc0ffee254729296a45a3885639AC7E10F9d54979'; - return { - resolvedAddresses: [ - { resolvedAddress, protocol: 'test protocol', domainName: domain }, - ], + const resolutions = { + fooBar: '0xc0ffee254729296a45a3885639AC7E10F9d54979', + bar: '0x0000000000000000000000000000000000000000', + barstool: '0x1234567890123456789012345678901234567890', }; + + const getResolution = (domainName: string) => { + if (resolutions[domainName]) { + return { + resolvedAddress: resolutions[domainName], + domainName, + protocol: 'test protocol', + }; + } + const entries = Object.entries(resolutions); + for (const [key, value] of entries) { + if (key.toLowerCase().startsWith(domainName.toLowerCase())) { + return { + domainName: key, + resolvedAddress: value, + protocol: 'test protocol', + }; + } + } + return null; + }; + const fetchedResolution = getResolution(domain); + if (fetchedResolution !== null) { + return { resolvedAddresses: [fetchedResolution] }; + } } return null;