Skip to content

Commit

Permalink
fix ark lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
maxknivets committed Oct 8, 2024
1 parent e1ce08c commit 2372efa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/hooks/useLambdaState.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useQuery } from '@tanstack/react-query';

export function useLambdaState() {
export function useLambdaState(addressHash: string) {
const { data, error, isLoading } = useQuery({
queryKey: [ 'lambda-state' ],
queryFn: async() => {
const response = await fetch('https://ark-lambda-api.vercel.app/api/ark-lambda');
queryKey: ['lambda-state', addressHash],
queryFn: async () => {
if (!addressHash) return null;
const response = await fetch(`https://ark-lambda-api.vercel.app/api/ark-lambda/eth-info?hash=${addressHash.toLowerCase()}`)
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
},
});
Expand Down
1 change: 1 addition & 0 deletions nextjs/csp/policies/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function ad(): CspDev.DirectiveDescriptor {
'coinzilla.com',
'*.coinzilla.com',
'https://ark-lambda-api.vercel.app',
'https://ark-lambda-api.vercel.app/api',
'https://request-global.czilladx.com',

// adbutler
Expand Down
8 changes: 4 additions & 4 deletions ui/address/AddressArweaveAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const Link = chakra((props: any) => {

const AddressArweaveAddress = ({ addressHash }: any) => {
const [arweaveAddress, setArweaveAddress] = useState<string | null>(null);
const { data, isLoading } = useLambdaState();
const { data, isLoading } = useLambdaState(addressHash);

const searchArksByKey = (state: any, ethereumAddress: string) => {
if (!ethereumAddress || !state) return null;
if (state.arks?.[ethereumAddress.toLowerCase()]) {
return { ethereumAddress: ethereumAddress.toLowerCase(), arweaveLinkings: state.arks[ethereumAddress.toLowerCase()][0].arweave_address, callTXID: state.arks[ethereumAddress.toLowerCase()][0].call_txid };
if (state?.ark) {
return { ethereumAddress: ethereumAddress.toLowerCase(), arweaveLinkings: state.ark[0].arweave_address, callTXID: state.ark[0].call_txid };
} else {
return null;
}
Expand All @@ -31,7 +31,7 @@ const AddressArweaveAddress = ({ addressHash }: any) => {
const fetchArweaveAddress = async () => {
if (addressHash && data) {
// @ts-ignore
const result = searchArksByKey(data?.data, addressHash);
const result = searchArksByKey(data, addressHash);
setArweaveAddress(result ? result.arweaveLinkings : null);
}
};
Expand Down

0 comments on commit 2372efa

Please sign in to comment.