-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web-Wallet cross-window login #7
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
83fa0ae
Turn relative imports into absolute
arhtudormorar 31ecb72
Work on simplify actions
arhtudormorar 5296d3c
Actions creator helper
arhtudormorar 2b89f1e
Refactor account definition
arhtudormorar 8378c72
Update network slice
arhtudormorar 58c0cff
Add login shared action
arhtudormorar b5130e2
Work on account login
arhtudormorar 99e8236
Update yarn lock
arhtudormorar 9c9b888
Update yarn lock
arhtudormorar b107d0d
Added nativeAuth services
arhtudormorar b95e391
Move services
arhtudormorar b9a5360
Add NativeAuth service
arhtudormorar 39b9bc9
Tests working
arhtudormorar ca97881
Compile working
arhtudormorar 0fe1aa0
0.0.0-alpha.2
arhtudormorar 58f0d8d
Update yarn.lock
arhtudormorar 74d1c1b
Update yarn lock
arhtudormorar 5e0a3db
Added validation
arhtudormorar a1d05ae
Add sanitizeCallbackUrl
arhtudormorar 4da1f4d
Upgrade version
arhtudormorar b66d97e
Work on deps
arhtudormorar 7ccfe89
Upgrade sdk-core
arhtudormorar fd4d268
Added buildUrlParams
arhtudormorar b6098e9
0.0.0-alpha.4
arhtudormorar 08b8379
remove lit
andreigiura 559bf54
upgrade cross-window
andreigiura 099e205
Revert version
arhtudormorar d97424c
Remove unused
arhtudormorar c987d39
Remove timeout promise
arhtudormorar a73883b
Account slice (#4)
arhtudormorar f86e0fa
Merge branch 'tm/feature/account-slice' into tm/network-slice
arhtudormorar c196b8c
New store structure
arhtudormorar e83ccdd
Rename useStore
arhtudormorar 58046ea
Expose getState
arhtudormorar 22f69c0
Add indexes
arhtudormorar 1464f15
Fixed import
arhtudormorar 1ea5a84
Work on login slice
arhtudormorar 88a003f
Create login info slice
arhtudormorar 41fdd4b
Work on login
arhtudormorar 16acbd0
Merge branch 'development' into tm/login
arhtudormorar 758bc13
Compiling
arhtudormorar 6f67f14
Add return type to web wallet login
arhtudormorar af75f16
Add default zero
arhtudormorar 5e32dbd
Resolve address
arhtudormorar ccb95cd
Move getLoginService to helpers
arhtudormorar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ACCOUNTS_ENDPOINT } from 'apiCalls/endpoints'; | ||
import { axiosInstance } from 'apiCalls/utils/axiosInstance'; | ||
import { getCleanApiAddress } from 'apiCalls/utils/getCleanApiAddress'; | ||
|
||
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); | ||
}; | ||
|
||
export const getAccountFromApi = async (address?: string) => { | ||
if (!address) { | ||
return null; | ||
} | ||
|
||
try { | ||
const { data } = await accountFetcher(address); | ||
return data; | ||
} 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'; |
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.
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,6 @@ | ||
import { accountSelector } from 'store/selectors'; | ||
import { getState } from 'store/store'; | ||
|
||
export function getAccount() { | ||
return accountSelector(getState()); | ||
} |
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,6 @@ | ||
import { addressSelector } from 'store/selectors'; | ||
import { getState } from 'store/store'; | ||
|
||
export function getAddress() { | ||
return addressSelector(getState()); | ||
} |
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,5 @@ | ||
import { getAddress } from './getAddress'; | ||
|
||
export function getIsLoggedIn() { | ||
return Boolean(getAddress()); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would catch and log the error here