Skip to content

Commit

Permalink
explorer api post to get method
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Jun 28, 2024
1 parent 30c2066 commit 894f241
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
32 changes: 19 additions & 13 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions frontend/src/ExplorerApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import axios from "axios";


import axios from 'axios';

export class ExplorerApiClient {


private url_api: string;

constructor() {
Expand All @@ -13,23 +9,27 @@ export class ExplorerApiClient {

async getDomainOwnedByAddress(address: string): Promise<string[]> {
return new Promise((resolve, reject) => {
axios.post(this.url_api + '/dns/addresses/owner', { addresses: [address] }).then((response) => {
resolve(response.data[address]);
}).catch((error) => {
console.error(error);
reject(error);
});
axios.get(this.url_api + '/dns/addresses/owner', { params: { addresses: [address] } })
.then((response) => {
resolve(response.data[address]);
})
.catch((error) => {
console.error(error);
reject(error);
});
});
}

async getDomainsInfo(domains: string[]): Promise<any> {
return new Promise((resolve, reject) => {
axios.post(this.url_api + '/dns/info', { dns: domains }).then((response) => {
resolve(response.data);
}).catch((error) => {
console.error(error);
reject(error);
});
axios.get(this.url_api + '/dns/info', { params: { dns: domains } })
.then((response) => {
resolve(response.data);
})
.catch((error) => {
console.error(error);
reject(error);
});
});
}
}
}
13 changes: 6 additions & 7 deletions frontend/src/utils/write-mns-sc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function useWriteMNS(client?: Client) {
const [opId, setOpId] = useState<string | undefined>(undefined);
const [list, setList] = useState<DnsUserEntryListResult[]>([]);
const [listSpinning, setListSpinning] = useState(false);
const explorer_api = new ExplorerApiClient();
const explorerApi = new ExplorerApiClient();

async function getAllocCost(
params: DnsAllocParams,
Expand Down Expand Up @@ -308,7 +308,6 @@ export function useWriteMNS(client?: Client) {
params: DnsUserEntryListParams,
): Promise<DnsUserEntryListResult[]> {
setListSpinning(true);
// let map_list_asked: Map<string, number> = new Map();
let resultBalance = await client?.smartContracts().readSmartContract({
targetAddress: SC_ADDRESS,
targetFunction: 'balanceOf',
Expand All @@ -322,15 +321,15 @@ export function useWriteMNS(client?: Client) {

let list: DnsUserEntryListResult[] = [];

let domains = await explorer_api.getDomainOwnedByAddress(params.address);
let domains = await explorerApi.getDomainOwnedByAddress(params.address);

let dns_infos = await explorer_api.getDomainsInfo(domains);
let dnsInfos = await explorerApi.getDomainsInfo(domains);

for (const domain in dns_infos) {
for (const domain in dnsInfos) {
list.push({
domain: domain,
targetAddress: dns_infos[domain].target_address,
tokenId: dns_infos[domain].tokenId,
targetAddress: dnsInfos[domain].target_address,
tokenId: dnsInfos[domain].tokenId,
});
}

Expand Down

0 comments on commit 894f241

Please sign in to comment.