Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

chore: rework into Pinia ORM #120

Merged
merged 49 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4d56e7f
Reorganize profile type
dzbo Oct 20, 2023
083fcbc
Verify creators
dzbo Oct 23, 2023
cae994c
Use short version
dzbo Oct 23, 2023
1eae789
Rename
dzbo Oct 23, 2023
8b43a5e
Merge branch 'feat/double-check-creator-address-DEV-8754' of github.c…
dzbo Oct 24, 2023
ae0c926
Move profile into model
dzbo Oct 25, 2023
5c2f7be
Cleanup old profile types
dzbo Oct 25, 2023
ada33d0
Move viewed profile into composition
dzbo Oct 25, 2023
109ebe5
Merge branch 'develop' of github.com:lukso-network/wallet.universalpr…
dzbo Oct 25, 2023
630d947
Cleanup
dzbo Oct 25, 2023
d8a4757
Rework profile logic in the app
dzbo Oct 25, 2023
f3ccae6
Change profile relationships
dzbo Oct 26, 2023
4900f63
Fix ref checks
dzbo Oct 26, 2023
6c7384d
Rework profile relationships
dzbo Oct 27, 2023
01fa9cc
Fix reactivity
dzbo Oct 27, 2023
c65f372
Simple reload when profile changes
dzbo Oct 27, 2023
7e54a3e
Profile load fixes
dzbo Oct 27, 2023
1e4c116
Rework assets
dzbo Oct 30, 2023
9777dc0
Fix issue with loading assets for first time
dzbo Oct 30, 2023
6206f6c
Cleanup
dzbo Oct 30, 2023
ed3098d
Show address in error
dzbo Oct 30, 2023
eb4b636
Rework creators
dzbo Oct 30, 2023
8a10cfd
Cleanup
dzbo Oct 30, 2023
a0b090c
Rename
dzbo Oct 30, 2023
c469532
Fix reactivity
dzbo Oct 30, 2023
9e6dc58
Update balance
dzbo Oct 30, 2023
518ddfa
Change asset pk
dzbo Oct 30, 2023
4b2b438
Rollback avatar change
dzbo Oct 30, 2023
7903a81
Simplify
dzbo Oct 30, 2023
ead4f0b
Change EoA check in search
dzbo Oct 30, 2023
890db03
Send changes
dzbo Oct 30, 2023
a3a7077
Remove nft after send
dzbo Oct 30, 2023
ec46038
Cleanup
dzbo Oct 30, 2023
f2246b9
Fix issue when no asset found
dzbo Oct 30, 2023
90de772
Upgrade LUKSO packages
dzbo Oct 30, 2023
6393816
Async balances
dzbo Oct 30, 2023
a97fc43
Fetch profile only once
dzbo Oct 30, 2023
f0705d5
Fix search
dzbo Oct 30, 2023
c791971
Remove factory
dzbo Oct 31, 2023
e237a13
Change asset show routes
dzbo Oct 31, 2023
d763d76
Navigate to home when no profile
dzbo Oct 31, 2023
5812e3c
Show send for own assets only
dzbo Oct 31, 2023
d75e9a1
feat: network switch (#121)
dzbo Nov 2, 2023
8a65ed3
Lint
dzbo Nov 2, 2023
5ae984c
Fix 404
dzbo Nov 2, 2023
a24816d
Update snapshots
dzbo Nov 2, 2023
8af1816
Load network before setting web3 instances
dzbo Nov 2, 2023
bac5bcf
Fix fresh page loading
dzbo Nov 2, 2023
1f18233
Fix tests
dzbo Nov 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 35 additions & 53 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,38 @@
import { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import { isAddress } from 'web3-utils'

import { fetchProfile } from '@/utils/fetchProfile'
import { assertString } from '@/utils/validators'

if (typeof window !== 'undefined') {
import('@lukso/web-components')
}

const web3Store = useWeb3Store()
const { getNetwork, selectedNetwork, modal } = useAppStore()
const { getNetwork } = useAppStore()
const { isLoadedApp, selectedChainId, modal } = storeToRefs(useAppStore())
const { addProviderEvents, removeProviderEvents, disconnect } =
useBrowserExtension()
const {
setProfile: setConnectedProfile,
setStatus,
profile: connectedProfile,
} = useConnectedProfileStore()
const router = useRouter()

const setupTranslations = () => {
useIntl().setupIntl(defaultConfig)
}

const setupWeb3Instances = () => {
const setupWeb3Instances = async () => {
const provider = INJECTED_PROVIDER

if (provider) {
// for chain interactions through wallet
web3Store.addWeb3(PROVIDERS.INJECTED, provider)
addProviderEvents(provider)
await addProviderEvents(provider)
// expose web3 instance to global scope for console access
window.web3 = web3Store.getWeb3(PROVIDERS.INJECTED)
} else {
console.error('No browser extension provider found')
}

// for chain interactions through RPC endpoint
web3Store.addWeb3(PROVIDERS.RPC, getNetwork(selectedNetwork).rpcHttp)
}

const setupConnectedProfile = async () => {
try {
const connectedAddress = getItem(STORAGE_KEY.CONNECTED_ADDRESS)

if (connectedAddress) {
assertAddress(connectedAddress, 'profile')
setStatus('isConnected', true)
setStatus('isProfileLoading', true)
const profile = await fetchProfile(connectedAddress)
connectedProfile.address = connectedAddress
setConnectedProfile(profile)
}
} catch (error) {
console.error(error)
} finally {
setStatus('isProfileLoading', false)
}
web3Store.addWeb3(PROVIDERS.RPC, getNetwork(selectedChainId.value).rpcHttp)
}

const routerBackProfileLoad = async () => {
Expand All @@ -70,20 +46,17 @@ const routerBackProfileLoad = async () => {
const fromProfileAddress = from.params?.profileAddress
const toProfileAddress = to.params?.profileAddress

if (!fromProfileAddress || !toProfileAddress) {
return next()
}

try {
assertString(toProfileAddress)
assertAddress(toProfileAddress, 'profile')

if (toProfileAddress !== fromProfileAddress) {
await loadViewedProfile(toProfileAddress)
await loadViewedAssets(toProfileAddress)
if (toProfileAddress) {
try {
assertString(toProfileAddress)
assertAddress(toProfileAddress, 'profile')
if (toProfileAddress !== fromProfileAddress) {
await fetchProfile(toProfileAddress)
await fetchAssets(toProfileAddress)
}
} catch (error) {
console.error(error)
}
} catch (error) {
console.error(error)
}
next()
}
Expand All @@ -100,9 +73,6 @@ const checkConnectionExpiry = () => {

if (expiryDateParsed < Date.now()) {
disconnect()
// we store address as this is "soft" disconnect that won't trigger request account on connection
connectedProfile.address &&
setItem(STORAGE_KEY.RECONNECT_ADDRESS, connectedProfile.address)
}
} catch (error) {}
}
Expand All @@ -124,26 +94,38 @@ const setupViewedProfile = async () => {

if (profileAddress) {
if (isAddress(profileAddress)) {
await loadViewedProfile(profileAddress)
await loadViewedAssets(profileAddress)
await fetchProfile(profileAddress)
await fetchAssets(profileAddress)
} else {
navigateTo(notFoundRoute())
}
}
} catch (error) {
} catch (error: unknown) {
console.error(error)

if (error instanceof EoAError) {
navigateTo(notFoundRoute()) // TODO we might want to inform user about EoA instead showing 404
}
}
}

const setupNetwork = async () => {
const chainId = (await INJECTED_PROVIDER?.request({
method: 'eth_chainId',
})) as string

selectedChainId.value = chainId
}

onMounted(async () => {
setupTranslations()
setupWeb3Instances()
await setupNetwork()
await setupWeb3Instances()
checkConnectionExpiry()
await setupConnectedProfile()
await setupViewedProfile()
await routerBackProfileLoad()
await setupViewedProfile()

setStatus('isProfileLoaded', true)
isLoadedApp.value = true

await setupCurrencies()
})
Expand All @@ -156,7 +138,7 @@ onUnmounted(() => {
useHead({
bodyAttrs: {
class: computed(() => {
if (modal?.isOpen) {
if (modal.value?.isOpen) {
return 'overflow-hidden'
}

Expand Down
15 changes: 8 additions & 7 deletions components/AppAvatar.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup lang="ts">
import makeBlockie from 'ethereum-blockies-base64'

import { Profile } from '@/models/profile'

type Props = {
isLoading?: boolean
isEoa?: boolean
isError?: boolean
address?: Address
profile?: Profile | Receiver
profile?: Profile
}

defineProps<Props>()
Expand All @@ -27,21 +28,21 @@ defineProps<Props>()
</div>
<div v-else-if="isEoa" class="flex flex-col items-center">
<lukso-profile
v-if="address"
v-if="profile?.address"
size="large"
:profile-url="makeBlockie(address)"
:profile-url="makeBlockie(profile.address)"
class="mb-2"
></lukso-profile>
<lukso-username
:address="address"
:address="profile?.address"
size="small"
slice-by="4"
></lukso-username>
</div>
<div v-else class="flex flex-col items-center">
<lukso-profile
size="large"
:profile-url="profile?.profileImageUrl"
:profile-url="profile?.profileImage?.base64"
:profile-address="profile?.address"
has-identicon
class="mb-2"
Expand All @@ -53,7 +54,7 @@ defineProps<Props>()
></lukso-username>
<lukso-username
v-else-if="profile?.address"
:address="profile?.address"
:address="profile.address"
size="small"
slice-by="4"
></lukso-username>
Expand Down
4 changes: 2 additions & 2 deletions components/AppButtonConnectOrInstall.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
const { connect, isUniversalProfileExtension } = useBrowserExtension()
const { status } = useConnectedProfileStore()
const { isConnecting } = storeToRefs(useAppStore())

const handleConnect = async () => {
connect()
Expand All @@ -27,7 +27,7 @@ const browserSupportExtension = extensionStore.url !== ''
variant="landing"
custom-class="mt-6"
is-full-width
:disabled="status.isConnecting ? true : undefined"
:disabled="isConnecting ? true : undefined"
>
{{ $formatMessage('connect_or_install_button_connect') }}
</lukso-button>
Expand Down
37 changes: 19 additions & 18 deletions components/AppNavbar.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<script setup lang="ts">
const { profile: connectedProfile, status } = useConnectedProfileStore()
const { connect, disconnect, isUniversalProfileExtension } =
useBrowserExtension()
const { profile: viewedProfile, reloadProfile } = useViewedProfileStore()
const { viewedProfile } = useViewedProfile()
const { connectedProfile } = useConnectedProfile()
const { isConnecting, isConnected, isTestnet } = storeToRefs(useAppStore())

const handleNavigateProfile = async () => {
try {
if (status.isConnected) {
assertAddress(connectedProfile.address, 'profile')
reloadProfile(connectedProfile)
navigateTo(profileRoute(connectedProfile.address))
if (isConnected.value) {
assertAddress(connectedProfile.value?.address, 'profile')
navigateTo(profileRoute(connectedProfile.value.address))
} else {
assertAddress(viewedProfile.address, 'profile')
navigateTo(profileRoute(viewedProfile.address))
assertAddress(viewedProfile.value?.address, 'profile')
navigateTo(profileRoute(viewedProfile.value.address))
}
} catch (error) {
console.error(error)
navigateTo(homeRoute())
}
}

const handleNavigateSend = () => {
try {
assertAddress(connectedProfile.address, 'profile')
navigateTo(sendRoute(connectedProfile.address))
assertAddress(connectedProfile.value?.address, 'profile')
navigateTo(sendRoute(connectedProfile.value.address))
} catch (error) {
console.error(error)
}
Expand Down Expand Up @@ -58,7 +59,7 @@ const browserSupportExtension = extensionStore.url !== ''
<lukso-navbar
is-sticky
:title="$formatMessage('header_title')"
:is-testnet="IS_TESTNET"
:is-testnet="isTestnet ? true : undefined"
icon="wallet-outline"
has-menu
@on-brand-click="handleNavigationDiscovery"
Expand All @@ -73,28 +74,28 @@ const browserSupportExtension = extensionStore.url !== ''
{{ $formatMessage('header_discovery') }}
</lukso-button>
<lukso-button
v-if="status.isConnected"
v-if="isConnected"
variant="text"
custom-class="text-purple-51 hover:text-purple-41 uppercase text-12 nav-apax-12-medium-uppercase font-apax font-500"
@click="handleNavigateSend"
>
{{ $formatMessage('header_send') }}
</lukso-button>
<lukso-button
v-if="status.isConnected"
v-if="isConnected"
variant="text"
custom-class="text-purple-51 hover:text-purple-41 uppercase text-12 nav-apax-12-medium-uppercase font-apax font-500"
@click="handleNavigateProfile"
>
{{ $formatMessage('header_my_profile') }}
</lukso-button>
<AppNavbarProfileDropdown v-if="status.isConnected" />
<AppNavbarProfileDropdown v-if="isConnected" />
<lukso-button
v-else-if="isUniversalProfileExtension()"
variant="secondary"
custom-class="text-purple-51 hover:text-purple-41 uppercase text-12 nav-apax-12-medium-uppercase font-apax font-500"
@click="handleConnect"
:is-loading="status.isConnecting ? true : undefined"
:is-loading="isConnecting ? true : undefined"
:loading-text="$formatMessage('header_connect')"
>
{{ $formatMessage('header_connect') }}
Expand All @@ -119,23 +120,23 @@ const browserSupportExtension = extensionStore.url !== ''
{{ $formatMessage('header_discovery') }}
</lukso-button>
<lukso-button
v-if="status.isConnected"
v-if="isConnected"
variant="text"
custom-class="text-purple-51 hover:text-purple-41 uppercase text-12 nav-apax-12-medium-uppercase font-apax font-500"
@click="handleNavigateSend"
>
{{ $formatMessage('header_send') }}
</lukso-button>
<lukso-button
v-if="status.isConnected"
v-if="isConnected"
variant="text"
custom-class="text-purple-51 hover:text-purple-41 uppercase text-12 nav-apax-12-medium-uppercase font-apax font-500"
@click="handleNavigateProfile"
>
{{ $formatMessage('header_my_profile') }}
</lukso-button>
<lukso-button
v-if="status.isConnected"
v-if="isConnected"
variant="text"
custom-class="text-purple-51 text-12 hover:text-purple-41 uppercase nav-apax-12-medium-uppercase font-apax font-500"
@click="handleDisconnect"
Expand Down
8 changes: 4 additions & 4 deletions components/AppNavbarProfileDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const { profile } = useConnectedProfileStore()
const { connectedProfile } = useConnectedProfile()
const { disconnect } = useBrowserExtension()

const DROPDOWN_TRIGGER_TAG_NAME = 'LUKSO-PROFILE'
Expand Down Expand Up @@ -35,10 +35,10 @@ onMounted(() => {
<div class="cursor-pointer relative">
<lukso-profile
size="small"
:profile-url="profile.profileImageUrl"
:profile-url="connectedProfile?.profileImage?.base64"
@click="handleToggleDropdown"
:profile-address="profile.address"
:data-profile-address="profile.address"
:profile-address="connectedProfile?.address"
:data-profile-address="connectedProfile?.address"
has-identicon
></lukso-profile>

Expand Down
4 changes: 2 additions & 2 deletions components/AssetBalance.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
type Props = {
balance: string
balance?: string
symbol?: string
decimals?: number
}
Expand All @@ -16,7 +16,7 @@ defineProps<Props>()
class="bg-neutral-100 border border-neutral-90 py-3 px-4 rounded-12 mb-8"
>
<div class="flex items-center justify-between paragraph-inter-14-regular">
{{ $formatNumber(fromWeiWithDecimals(balance, decimals)) }}
{{ $formatNumber(fromWeiWithDecimals(balance || '', decimals)) }}
<div
class="paragraph-inter-12-regular text-neutral-60 border-l border-l-neutral-90 pl-3 ml-3"
>
Expand Down
Loading