-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from tonwhales/release/v2.1.15
Release/v2.1.15
- Loading branch information
Showing
25 changed files
with
445 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
208 | ||
209 |
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,30 @@ | ||
import axios from "axios"; | ||
import { z } from "zod"; | ||
|
||
const jettonPayloadScheme = z.object({ | ||
customPayload: z.string().optional().nullable(), | ||
stateInit: z.string().optional().nullable() | ||
}); | ||
|
||
export type JettonPayload = z.infer<typeof jettonPayloadScheme>; | ||
|
||
export async function fetchJettonPayload(account: string, jettonMaster: string, customPayloadApiUri?: string | null): Promise<JettonPayload> { | ||
const endpoint = `https://connect.tonhubapi.com/mintless/jettons/`; | ||
const path = `${jettonMaster}/transfer/${account}/payload`; | ||
|
||
const searchParams = new URLSearchParams(); | ||
if (customPayloadApiUri) { | ||
searchParams.append('customPayloadApiUri', customPayloadApiUri); | ||
} | ||
const search = searchParams.toString(); | ||
const url = `${endpoint}${path}${search ? `?${search}` : ''}`; | ||
const res = (await axios.get(url)).data; | ||
|
||
const parsed = jettonPayloadScheme.safeParse(res); | ||
|
||
if (!parsed.success) { | ||
throw Error('Invalid jetton payload'); | ||
} | ||
|
||
return parsed.data; | ||
} |
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,48 @@ | ||
import axios from "axios"; | ||
import { z } from "zod"; | ||
|
||
const mintlessJettonScheme = z.object({ | ||
balance: z.string(), | ||
walletAddress: z.object({ | ||
address: z.string(), | ||
name: z.string().optional().nullable(), | ||
icon: z.string().optional().nullable(), | ||
isScam: z.boolean(), | ||
isWallet: z.boolean() | ||
}), | ||
price: z.object({ | ||
prices: z.record(z.number()).optional().nullable(), | ||
diff24h: z.record(z.string()).optional().nullable(), | ||
diff7d: z.record(z.string()).optional().nullable(), | ||
diff30d: z.record(z.string()).optional().nullable() | ||
}).optional().nullable(), | ||
jetton: z.object({ | ||
address: z.string(), | ||
name: z.string(), | ||
symbol: z.string(), | ||
decimals: z.number(), | ||
image: z.string(), | ||
verification: z.string(), | ||
customPayloadApiUri: z.string().nullable().optional() | ||
}), | ||
extensions: z.array(z.string()), | ||
lock: z.object({ | ||
amount: z.string(), | ||
till: z.number() | ||
}).optional().nullable() | ||
}); | ||
const mintlessJettonListScheme = z.array(mintlessJettonScheme); | ||
|
||
export type MintlessJetton = z.infer<typeof mintlessJettonScheme>; | ||
|
||
export async function fetchMintlessHints(address: string): Promise<MintlessJetton[]> { | ||
let res = (await axios.get(`https://connect.tonhubapi.com/mintless/jettons/${address}`)).data; | ||
|
||
const parsed = mintlessJettonListScheme.safeParse(res); | ||
|
||
if (!parsed.success) { | ||
throw Error('Invalid mintless hints'); | ||
} | ||
|
||
return parsed.data; | ||
} |
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,42 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Queries } from "../../queries"; | ||
import { fetchJettonPayload } from "../../api/fetchJettonPayload"; | ||
import { queryClient } from "../../clients"; | ||
import { getQueryData } from "../../utils/getQueryData"; | ||
import { MintlessJetton } from "../../api/fetchMintlessHints"; | ||
import { Address } from "@ton/core"; | ||
|
||
export function useJettonPayload(account?: string, masterAddress?: string) { | ||
const enabled = !!account && !!masterAddress; | ||
|
||
const query = useQuery({ | ||
queryKey: Queries.Jettons().Address(account || '').WalletPayload(masterAddress || ''), | ||
queryFn: async () => { | ||
if (!account || !masterAddress) { | ||
return null; | ||
} | ||
|
||
const queryCache = queryClient.getQueryCache(); | ||
const mintlessHints = getQueryData<MintlessJetton[]>(queryCache, Queries.Mintless(account!)) || []; | ||
const mintlessJetton = mintlessHints.find(h => Address.parse(masterAddress).equals(Address.parse(h.jetton.address)))?.jetton; | ||
|
||
if (!mintlessJetton) { | ||
return null; | ||
} | ||
|
||
const customPayloadApiUri = mintlessJetton.customPayloadApiUri; | ||
const res = await fetchJettonPayload(account!, masterAddress!, customPayloadApiUri); | ||
return res; | ||
}, | ||
enabled, | ||
staleTime: 1000 * 5, | ||
refetchOnMount: true, | ||
refetchOnWindowFocus: true | ||
}); | ||
|
||
return { | ||
data: query.data, | ||
loading: (query.isFetching || query.isLoading) && enabled, | ||
isError: query.isError, | ||
} | ||
} |
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
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
Oops, something went wrong.