-
Notifications
You must be signed in to change notification settings - Fork 0
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 #17 from multiversx/development
v0.0.0-alpha.9
- Loading branch information
Showing
126 changed files
with
4,628 additions
and
1,032 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ACCOUNTS_ENDPOINT } from 'apiCalls/endpoints'; | ||
import { axiosInstance } from 'apiCalls/utils/axiosInstance'; | ||
import { getCleanApiAddress } from 'apiCalls/utils/getCleanApiAddress'; | ||
import { AccountType } from 'types/account.types'; | ||
|
||
export const accountFetcher = (address: string | null) => { | ||
const apiAddress = getCleanApiAddress(); | ||
const url = `${apiAddress}/${ACCOUNTS_ENDPOINT}/${address}?withGuardianInfo=true`; | ||
// we need to get it with an axios instance because of cross-window user interaction issues | ||
return axiosInstance.get(url, { | ||
baseURL: apiAddress | ||
}); | ||
}; | ||
|
||
export const getAccountFromApi = async (address?: string) => { | ||
if (!address) { | ||
return null; | ||
} | ||
|
||
try { | ||
const { data } = await accountFetcher(address); | ||
return data as AccountType; | ||
} catch (err) { | ||
console.error('error fetching configuration for ', address); | ||
} | ||
|
||
return null; | ||
}; |
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 @@ | ||
export * from './getAccountFromApi'; |
5 changes: 3 additions & 2 deletions
5
...ces/network/actions/getCleanApiAddress.ts → ...Calls/configuration/getCleanApiAddress.ts
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,8 @@ | ||
import { networkStore } from '../network'; | ||
import { networkSelector } from 'store/selectors/networkSelectors'; | ||
import { getState } from 'store/store'; | ||
|
||
export const getCleanApiAddress = (customApiAddress?: string) => { | ||
const { network } = networkStore.getState(); | ||
const network = networkSelector(getState()); | ||
const apiAddress = customApiAddress ?? network.apiAddress; | ||
return apiAddress.endsWith('/') ? apiAddress.slice(0, -1) : apiAddress; | ||
}; |
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,4 @@ | ||
import { axiosInstance } from 'apiCalls/utils/axiosInstance'; | ||
|
||
export const axiosFetcher = (url: string) => | ||
axiosInstance.get(url).then((response) => response.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,99 @@ | ||
import { buildAxiosFetch } from '@lifeomic/axios-fetch'; | ||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
|
||
// Needs to be used beacause an async call made after cross-window user interaction makes the dapp unresponsive | ||
|
||
const fetch = buildAxiosFetch(axios); | ||
|
||
const getFormattedAxiosResponse = async <T>(response: Response, config?: T) => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
|
||
// Clone the response to be able to read it twice (for status and data) | ||
const clonedResponse = response.clone(); | ||
|
||
// Parse the JSON body asynchronously | ||
const jsonPromise = clonedResponse.json(); | ||
|
||
// Return the standardized response object | ||
const [responseData] = await Promise.all([jsonPromise]); | ||
return { | ||
data: responseData, | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: response.headers, | ||
config | ||
}; | ||
}; | ||
|
||
async function customPost<T = any, R = AxiosResponse<T, any>, D = any>( | ||
url: string, | ||
data?: D, | ||
config?: AxiosRequestConfig<D> | undefined | ||
): Promise<R> { | ||
try { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
body: data ? JSON.stringify(data) : undefined, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...(config?.headers || {}) | ||
}, | ||
...config | ||
} as RequestInit); | ||
|
||
return getFormattedAxiosResponse(response, config) as unknown as Promise<R>; | ||
} catch (error) { | ||
console.error('Fetch Error:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async function customGet<T = any, R = AxiosResponse<T, any>, D = any>( | ||
url: string, | ||
config?: AxiosRequestConfig<D> | undefined | ||
): Promise<R> { | ||
try { | ||
const response = await fetch(url, config as RequestInit); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
|
||
return getFormattedAxiosResponse(response, config) as unknown as Promise<R>; | ||
} catch (error) { | ||
console.error('Fetch Error:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async function customPatch<T = any, R = AxiosResponse<T, any>, D = any>( | ||
url: string, | ||
data?: D, | ||
config?: AxiosRequestConfig<D> | undefined | ||
): Promise<R> { | ||
try { | ||
const response = await fetch(url, { | ||
method: 'PATCH', | ||
body: data ? JSON.stringify(data) : undefined, | ||
headers: config?.headers || {}, | ||
...config | ||
} as RequestInit); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
|
||
return getFormattedAxiosResponse(response, config) as unknown as Promise<R>; | ||
} catch (error) { | ||
console.error('Fetch Error:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
const axiosInstance = axios.create(); | ||
axiosInstance.get = customGet; | ||
axiosInstance.post = customPost; | ||
axiosInstance.patch = customPatch; | ||
|
||
export { axiosInstance }; |
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,8 @@ | ||
import { networkSelector } from 'store/selectors/networkSelectors'; | ||
import { getState } from 'store/store'; | ||
|
||
export const getCleanApiAddress = (customApiAddress?: string) => { | ||
const network = networkSelector(getState()); | ||
const apiAddress = customApiAddress ?? network.apiAddress; | ||
return apiAddress.endsWith('/') ? apiAddress.slice(0, -1) : apiAddress; | ||
}; |
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,18 @@ | ||
import axios from 'axios'; | ||
import { ScamInfoType } from 'types/account.types'; | ||
import { ACCOUNTS_ENDPOINT } from '../endpoints'; | ||
import { networkSelector } from 'store/selectors'; | ||
import { getState } from 'store/store'; | ||
|
||
export async function getScamAddressData(addressToVerify: string) { | ||
const { apiAddress, apiTimeout } = networkSelector(getState()); | ||
|
||
const { data } = await axios.get<{ | ||
scamInfo?: ScamInfoType; | ||
code?: string; | ||
}>(`${apiAddress}/${ACCOUNTS_ENDPOINT}/${addressToVerify}`, { | ||
timeout: Number(apiTimeout) | ||
}); | ||
|
||
return 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,4 @@ | ||
export * from './axiosFetcher'; | ||
export * from './axiosInstance'; | ||
export * from './getCleanApiAddress'; | ||
export * from './getScamAddressData'; |
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,10 @@ | ||
import { safeWindow } from './window.constants'; | ||
|
||
const userAgent = String(safeWindow?.navigator?.userAgent); | ||
|
||
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent); | ||
|
||
const isFirefoxOnWindows = | ||
/firefox/i.test(userAgent) && /windows/i.test(userAgent); | ||
|
||
export const isBrowserWithPopupConfirmation = isSafari || isFirefoxOnWindows; |
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,13 @@ | ||
export const ERROR_SIGNING = 'error when signing'; | ||
export const CANCELLED = 'cancelled'; | ||
export const TRANSACTION_CANCELLED = 'Transaction canceled'; | ||
export const ERROR_SIGNING_TX = 'error signing transaction'; | ||
export const PROVIDER_NOT_INITIALIZED = 'provider not initialized'; | ||
export const MISSING_PROVIDER_MESSAGE = | ||
'You need a signer/valid signer to send a transaction,use either WalletProvider, LedgerProvider or WalletConnect'; | ||
export const DEFAULT_TRANSACTION_STATUS_MESSAGE = | ||
'Undefined transaction status'; | ||
export const SECOND_LOGIN_ATTEMPT_ERROR = | ||
'Action not allowed. User is logged in. Call logout() first'; | ||
export const SENDER_DIFFERENT_THAN_LOGGED_IN_ADDRESS = | ||
'You cannot sign transactions from a different account'; |
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,4 +1,7 @@ | ||
export * from './network'; | ||
export * from './placeholders'; | ||
export * from './storage'; | ||
export * from './window'; | ||
export * from './network.constants'; | ||
export * from './placeholders.constants'; | ||
export * from './storage.constants'; | ||
export * from './window.constants'; | ||
export * from './browser.constants'; | ||
export * from './errorMessages.constants'; | ||
export * from './ledger.constants'; |
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 @@ | ||
export const LEDGER_CONTRACT_DATA_ENABLED_VALUE = 1; |
File renamed without changes.
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,8 @@ | ||
/** | ||
* Not Applicable | ||
* @value N/A | ||
*/ | ||
export const N_A = 'N/A'; | ||
|
||
export const ZERO = '0'; | ||
export const ELLIPSIS = '...'; |
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
File renamed without changes.
Oops, something went wrong.