This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8179e4e
commit fe2000e
Showing
5 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "algoworld-swapper", | ||
"description": "Free and trustless ASA swapper, powered by Algorand ⚡️", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"private": true, | ||
"author": "AlgoWorld <[email protected]>", | ||
"license": "GPL-3.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ChainType } from '@/models/Chain'; | ||
import axios from 'axios'; | ||
import getNFDsForAddress from './getNFDsForAddress'; | ||
|
||
jest.mock(`axios`); | ||
|
||
describe(`getNFDsForAddress`, () => { | ||
it(`should return the NFD for the given address on mainnet`, async () => { | ||
const address = `tnaq9cjf54ct59bmua78iuv6gtpjtdunc78q8jebwgmxyacb`; | ||
const chain = ChainType.MainNet; | ||
const nfd = { name: `test-nfd` }; | ||
const response = { data: [nfd] }; | ||
|
||
(axios.get as jest.MockedFunction<typeof axios.get>).mockResolvedValue( | ||
response, | ||
); | ||
|
||
const result = await getNFDsForAddress(address, chain); | ||
expect(result).toEqual(nfd); | ||
}); | ||
|
||
it(`should return the NFD for the given address on testnet`, async () => { | ||
const address = `tnaq9cjf54ct59bmua78iuv6gtpjtdunc78q8jebwgmxyacb`; | ||
const chain = ChainType.TestNet; | ||
const nfd = { name: `test-nfd` }; | ||
const response = { data: [nfd] }; | ||
|
||
(axios.get as jest.MockedFunction<typeof axios.get>).mockResolvedValue( | ||
response, | ||
); | ||
|
||
const result = await getNFDsForAddress(address, chain); | ||
expect(result).toEqual(nfd); | ||
}); | ||
|
||
it(`should return null if the NFD is not found`, async () => { | ||
const address = `tnaq9cjf54ct59bmua78iuv6gtpjtdunc78q8jebwgmxyacb`; | ||
const chain = ChainType.MainNet; | ||
const response = { data: [] }; | ||
|
||
(axios.get as jest.MockedFunction<typeof axios.get>).mockResolvedValue( | ||
response, | ||
); | ||
|
||
const result = await getNFDsForAddress(address, chain); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it(`should return null if the request fails`, async () => { | ||
const address = `tnaq9cjf54ct59bmua78iuv6gtpjtdunc78q8jebwgmxyacb`; | ||
const chain = ChainType.MainNet; | ||
|
||
(axios.get as jest.MockedFunction<typeof axios.get>).mockRejectedValue( | ||
new Error(`Request failed`), | ||
); | ||
|
||
const result = await getNFDsForAddress(address, chain); | ||
expect(result).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ChainType } from '@/models/Chain'; | ||
import axios from 'axios'; | ||
|
||
const NFD_MAINNET = `https://api.nf.domains`; | ||
const NFD_TESTNET = `https://api.testnet.nf.domains`; | ||
|
||
const getNFDsForAddress = async (address: string, chain: ChainType) => { | ||
try { | ||
const url = `${ | ||
chain === ChainType.MainNet ? NFD_MAINNET : NFD_TESTNET | ||
}/nfd`; | ||
const response = await axios.get(url, { | ||
params: { | ||
owner: address, | ||
}, | ||
}); | ||
return response.data.length > 0 ? response.data[0] : null; | ||
} catch (error) { | ||
// handle error | ||
return null; | ||
} | ||
}; | ||
|
||
export default getNFDsForAddress; |
fe2000e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for algoworld-swapper ready!
✅ Preview
https://algoworld-swapper-cht2zuu1k-algoworldexplorer.vercel.app
Built with commit fe2000e.
This pull request is being automatically deployed with vercel-action