This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
163 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
import { SelectStringOption } from '@lukso/web-components' | ||
const networks = ref<SelectStringOption[]>() | ||
const selectedNetwork = ref<SelectStringOption>() | ||
const { currentNetwork, selectedChainId } = storeToRefs(useAppStore()) | ||
const { disconnect } = useBrowserExtension() | ||
const { isMobileOrTablet } = useDevice() | ||
const isOpen = ref(false) | ||
onMounted(() => { | ||
networks.value = NETWORKS.map(network => { | ||
return { | ||
id: network.chainId, | ||
value: network.name, | ||
} | ||
}) | ||
}) | ||
watchEffect(() => { | ||
selectedNetwork.value = { | ||
id: currentNetwork.value.chainId, | ||
value: currentNetwork.value.name, | ||
} | ||
}) | ||
const handleNetworkChange = (event: CustomEvent) => { | ||
const selectedNetwork = event.detail.value as SelectStringOption | ||
selectedNetwork.id && (selectedChainId.value = selectedNetwork.id) | ||
disconnect() | ||
navigateTo(homeRoute()) | ||
} | ||
</script> | ||
|
||
<template> | ||
<lukso-select | ||
:value="JSON.stringify(selectedNetwork)" | ||
:options="JSON.stringify(networks)" | ||
:open-top="!isMobileOrTablet ? true : undefined" | ||
:is-open="isOpen ? true : undefined" | ||
:is-full-width="isMobileOrTablet ? true : undefined" | ||
class="sm:w-40" | ||
@on-select="handleNetworkChange" | ||
></lukso-select> | ||
</template> |
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,57 @@ | ||
<script setup lang="ts"> | ||
const { currentNetwork } = useAppStore() | ||
type Props = { | ||
closeModal: () => void | ||
} | ||
const props = defineProps<Props>() | ||
const handleChangeNetwork = async () => { | ||
try { | ||
await INJECTED_PROVIDER?.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [{ chainId: currentNetwork.chainId }], | ||
}) | ||
} catch (error: unknown) { | ||
console.error(error) | ||
} finally { | ||
props.closeModal() | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="bg-neutral-98 text-center p-6 rounded-12 flex flex-col"> | ||
<img | ||
src="/images/switch-network.png" | ||
class="mx-auto w-[150px] mb-6" | ||
alt="" | ||
/> | ||
<div class="heading-inter-21-semi-bold pb-4"> | ||
{{ $formatMessage('modal_switch_network_title') }} | ||
</div> | ||
<div class="paragraph-inter-16-regular"> | ||
<lukso-sanitize | ||
:html-content=" | ||
$formatMessage('modal_switch_network_description', { | ||
name: `<strong>${currentNetwork.name}</strong>`, | ||
}) | ||
" | ||
></lukso-sanitize> | ||
</div> | ||
<div class="grid grid-cols-[max-content,auto]"> | ||
<lukso-button variant="text" @click="closeModal" class="mt-6"> | ||
{{ $formatMessage('modal_switch_network_cancel') }} | ||
</lukso-button> | ||
<lukso-button | ||
variant="landing" | ||
is-full-width | ||
@click="handleChangeNetwork" | ||
class="mt-6" | ||
> | ||
{{ $formatMessage('modal_switch_network_confirm') }} | ||
</lukso-button> | ||
</div> | ||
</div> | ||
</template> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.15 KB
(100%)
tests/e2e/index.spec.ts-snapshots/landing-no-extension-chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
export const checkNetwork = async () => { | ||
const { currentNetwork } = useAppStore() | ||
const { showModal } = useModal() | ||
const chainId = (await INJECTED_PROVIDER?.request({ | ||
method: 'eth_chainId', | ||
})) as string | ||
|
||
if (currentNetwork.chainId !== chainId) { | ||
showModal({ | ||
template: 'SwitchNetwork', | ||
}) | ||
|
||
throw new Error('Wrong network') | ||
} | ||
} |
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,51 +1,37 @@ | ||
export const getConnectionErrorMessage = (error: unknown) => { | ||
export const getErrorMessage = (error: unknown) => { | ||
const { formatMessage } = useIntl() | ||
const { currentNetwork } = useAppStore() | ||
|
||
// known error types | ||
if (error instanceof EoAError) { | ||
return formatMessage('web3_eoa_error_message') | ||
return formatMessage('error_eoa') | ||
} | ||
|
||
if (error instanceof InterfaceError) { | ||
return formatMessage('web3_interface_error_message') | ||
return formatMessage('error_invalid_profile_interface') | ||
} | ||
|
||
// errors that have a code or message | ||
if (error && typeof error === 'object' && 'code' in error) { | ||
switch (error.code) { | ||
case 4001: | ||
return formatMessage('web3_connect_error_rejected_request') | ||
return formatMessage('error_rejected_request') | ||
case -32005: | ||
return formatMessage('web3_connect_error_pending_request') | ||
return formatMessage('error_pending_request') | ||
case -32001: | ||
return formatMessage('web3_connect_error_no_profiles') | ||
default: | ||
break | ||
} | ||
} | ||
|
||
// generic message for unknowns errors | ||
return formatMessage('web3_connect_error') | ||
} | ||
|
||
export const getSendErrorMessage = (error: unknown): string => { | ||
const { formatMessage } = useIntl() | ||
const appStore = useAppStore() | ||
|
||
// errors that have a code or message | ||
if (error && typeof error === 'object' && 'code' in error) { | ||
switch (error.code) { | ||
case 4001: | ||
return formatMessage('send_error_rejected_request') | ||
return formatMessage('error_no_profiles') | ||
case -32600: | ||
return formatMessage('error_no_accounts') | ||
case -32601: | ||
case -32602: | ||
return formatMessage('send_error_same_address', { | ||
lyxSymbol: appStore.currentNetwork.token.symbol, | ||
return formatMessage('error_same_address', { | ||
lyxSymbol: currentNetwork.token.symbol, | ||
}) | ||
default: | ||
break | ||
} | ||
} | ||
|
||
// generic message for unknowns errors | ||
return formatMessage('send_error_message') | ||
return formatMessage('web3_connect_error') | ||
} |
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