Skip to content

Commit

Permalink
fixup! feat: add GET_ADA_HANDLE command
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Nov 18, 2024
1 parent 699264d commit 8f580ec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/methods/get-ada-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BlockfrostServerError } from '@blockfrost/blockfrost-js';
const policyID = 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a';

export default async (id: MessageId, clientId: string, name: string): Promise<string> => {
let data: string | null;
let data: { address: string } | null;

try {
const result = await blockfrostAPI.assetsAddresses(
Expand All @@ -17,7 +17,13 @@ export default async (id: MessageId, clientId: string, name: string): Promise<st
throw new Error('Double minted Ada Handle detected');
}

data = result.length === 0 ? null : result[0].address;
if (result.length === 0) {
data = null;
} else {
const { address } = result[0];

data = { address };
}
} catch (error) {
if (error instanceof BlockfrostServerError && error.status_code === 404) {
data = null;
Expand Down
1 change: 1 addition & 0 deletions src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type Responses = {
| ServerInfo
| AccountInfo
| string
| { address: string }
| null
| Schemas['block_content']
| BalanceHistoryData[]
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/preprod/get-ada-handle.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default [
{
handle: 'test',
testName: 'GET_ADA_HANDLE success - preprod',
result: expect.any(String),
result: { address: expect.any(String) },
},
{
handle: 'does_not_exist',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixtures/getAdaHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
result: {
id: 1,
type: 'message',
data: 'address',
data: { address: 'address' },
},
},
{
Expand Down

0 comments on commit 8f580ec

Please sign in to comment.