Skip to content

Commit

Permalink
Merge branch 'main' into issue-10708
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiival authored Aug 22, 2024
2 parents f51f31e + 56a57bb commit 82c92a0
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 53 deletions.
5 changes: 3 additions & 2 deletions components/collection/drop/GenerativePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{{ mintedPercent }}% ~
</div>
<div
v-if="drop.minted >= 0 && drop.max"
v-if="!getIsLoadingMaxCount"
class="font-bold flex gap-2"
>
<span>{{ drop.minted }}</span>
Expand Down Expand Up @@ -113,12 +113,13 @@ import useGenerativeIframeData from '@/composables/drop/useGenerativeIframeData'
const { accountId } = useAuth()
const { chainSymbol, decimals } = useChain()
const dropStore = useDropStore()
const { userMintsCount, drop } = storeToRefs(dropStore)
const { userMintsCount, drop, getIsLoadingMaxCount } = storeToRefs(dropStore)
const { imageDataPayload, imageDataLoaded } = useGenerativeIframeData()
const { formatted: formattedPrice } = useAmount(
computed(() => drop.value.price),
decimals,
chainSymbol,
computed(() => drop.value.chain),
)
const emit = defineEmits(['generation:start', 'generation:end', 'mint'])
Expand Down
7 changes: 4 additions & 3 deletions components/collection/drop/MintButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const dropStore = useDropStore()
const { hasCurrentChainBalance } = useMultipleBalance()
const now = useNow()
const { mintCountAvailable } = useGenerativeDropMint()
const { amountToMint, previewItem, userMintsCount, drop } = storeToRefs(dropStore)
const { amountToMint, previewItem, userMintsCount, drop, getIsLoadingMaxCount } = storeToRefs(dropStore)
const { hasMinimumFunds } = useDropMinimumFunds()
const { holderOfCollection } = useHolderOfCollection()
Expand All @@ -67,7 +67,7 @@ watch(drop, async () => {
const mintForLabel = computed(() =>
$i18n.t('drops.mintForPaid', [
`${formatAmountWithRound(drop.value?.price ? Number(drop.value?.price) * amountToMint.value : '', decimals.value)} ${
`${formatAmountWithRound(drop.value?.price ? Number(drop.value?.price) * amountToMint.value : '', decimals.value, drop.value.chain)} ${
chainSymbol.value
} ${priceUsd.value ? '/ ' + (priceUsd.value * amountToMint.value).toFixed(2) + ' ' + $i18n.t('general.usd') : ''}`,
]),
Expand Down Expand Up @@ -152,7 +152,8 @@ const loading = computed(
() =>
dropStore.isCapturingImage
|| dropStore.walletConnecting
|| dropStore.loading,
|| dropStore.loading
|| getIsLoadingMaxCount.value,
)
const showHolderOfCollection = computed(() =>
Expand Down
14 changes: 7 additions & 7 deletions components/common/ConnectWallet/WalletAssetMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@

<script setup lang="ts">
import { NeoDropdown, NeoDropdownItem, NeoIcon } from '@kodadot1/brick'
import type { ChainVM } from '@kodadot1/static'
import type { Prefix } from '@kodadot1/static'
import { langsFlags, setUserLocale } from '@/utils/config/i18n'
import { transferVisible, teleportVisible, migrateVisible } from '@/utils/config/permission.config'
const { urlPrefix } = usePrefix()
const { vm } = useChain()
// const { isAssetHub } = useIsChain(urlPrefix)
const { neoModal } = useProgrammatic()
const menus = ref<{ label: string, to: string, vm: ChainVM[] }[]>([
const menus = ref<{ label: string, to: string, check: (v: Prefix) => boolean }[]>([
{
label: 'Transfer',
to: `/${urlPrefix.value}/transfer`,
vm: ['SUB'],
check: transferVisible,
},
{
label: 'Teleport Bridge',
to: `/${urlPrefix.value}/teleport`,
vm: ['SUB'],
check: teleportVisible,
},
{
label: 'Migrate',
to: '/migrate',
vm: ['SUB'],
check: migrateVisible,
},
])
Expand All @@ -122,7 +122,7 @@ const menus = ref<{ label: string, to: string, vm: ChainVM[] }[]>([
// })
const filteredMenus = computed(() =>
menus.value.filter(menu => menu.vm.includes(vm.value)),
menus.value.filter(menu => menu.check(urlPrefix.value)),
)
const closeModal = () => {
Expand Down
3 changes: 1 addition & 2 deletions components/drops/BasicDropCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
class="h-[28px] flex justify-between items-center gap-y-4 gap-x-2"
>
<div
v-if="dropStatus !== 'scheduled_soon'"
class="flex gap-4"
class="flex shrink-0 gap-4"
>
<slot name="supply">
<div>
Expand Down
2 changes: 1 addition & 1 deletion components/drops/TimeTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const displayText = computed(() => {
case DropStatus.MINTING_LIVE:
return $i18n.t('drops.mintingNow')
case DropStatus.SCHEDULED_SOON:
return toDropScheduledDurationString(props.dropStartTime as Date)
return toDropScheduledDurationString(props.dropStartTime as Date, true)
case DropStatus.SCHEDULED:
return formatDropStartTime(
props.dropStartTime as Date,
Expand Down
23 changes: 20 additions & 3 deletions components/drops/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { formatDuration, intervalToDuration, intlFormat } from 'date-fns'

export function toDropScheduledDurationString(startTime: Date) {
export function toDropScheduledDurationString(startTime: Date, short: boolean = false) {
const duration = intervalToDuration({
start: startTime,
end: new Date(),
})
return formatDuration(duration, {

const options = {
format: ['hours', 'minutes'],
})
}

if (short) {
Object.assign(options, {
locale: {
formatDistance: (token: string, count: string) => {
return {
xHours: '{{count}}h',
xMinutes: '{{count}}m',
xSeconds: '{{count}}s',
}?.[token]?.replace('{{count}}', count)
},
} as Locale,
})
}

return formatDuration(duration, options)
}

export function formatDropStartTime(
Expand Down
20 changes: 11 additions & 9 deletions composables/transaction/evm/useMetaTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@ export default function useEvmMetaTransaction() {

const txHash = await writeContract(wagmiConfig, request)
console.log('[EXEC] Executed', txHash)
status.value = TransactionStatus.Broadcast

successCb(onSuccess)({ txHash })
const transaction = await waitForTransactionReceipt(wagmiConfig, { hash: txHash })
console.log('[EXEC] Completed', transaction)

const map = {
success: () => successCb(onSuccess)({ txHash, blockNumber: transaction.blockNumber.toString() }),
reverted: () => errorCb(onError)({ error: new Error('Transaction reverted') }),
}

map[transaction.status]?.()
}
catch (e) {
errorCb(onError)({ error: e })
Expand All @@ -72,14 +81,7 @@ export default function useEvmMetaTransaction() {

const successCb
= (onSuccess?: (param: EvmHowAboutToExecuteOnSuccessParam) => void) =>
async ({ txHash }) => {
const transaciton = await waitForTransactionReceipt(wagmiConfig, {
hash: txHash,
})
const blockNumber = transaciton.blockNumber.toString()

console.log('[EXEC] Completed', transaciton)

async ({ txHash, blockNumber }) => {
if (onSuccess) {
onSuccess({ txHash: txHash, blockNumber: blockNumber })
}
Expand Down
5 changes: 3 additions & 2 deletions composables/useAmount.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { Prefix } from '@kodadot1/static'
import { formatAmountWithRound } from '@/utils/format/balance'

export default function (
tokenAmount: ComputedRef<number | string | undefined>,
tokenDecimals: ComputedRef<number>,
chainSymbol: ComputedRef<string>,
round: undefined | number = undefined,
roundBy?: ComputedRef<Prefix | number>,
) {
const { getCurrentTokenValue } = useFiatStore()

const amountFormatted = computed(() => {
const amount = tokenAmount.value
? formatAmountWithRound(tokenAmount.value, tokenDecimals.value, round)
? formatAmountWithRound(tokenAmount.value, tokenDecimals.value, roundBy?.value)
: 0
return `${amount} ${chainSymbol.value}`
})
Expand Down
5 changes: 2 additions & 3 deletions composables/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ const getUniqueArrayItems = (items: string[]) => [...new Set(items)]
export default function useToken() {
const { getCurrentTokenValue } = useFiatStore()
const { getTokenIconBySymbol } = useIcon()
const { multiBalanceAssets } = useIdentityStore()
const { getVmAssets } = storeToRefs(useIdentityStore())

const availableAssets = computed(() => multiBalanceAssets)
const availableTokensAcrossAllChains = computed(() =>
getUniqueArrayItems(
Object.values(availableAssets.value).map(getAssetToken),
Object.values(getVmAssets.value).map(getAssetToken),
),
)

Expand Down
32 changes: 20 additions & 12 deletions middleware/redirects.global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { createVisible } from '@/utils/config/permission.config'
import { type Prefix } from '@kodadot1/static'
import { createVisible, transferVisible, teleportVisible, migrateVisible } from '@/utils/config/permission.config'

export default defineNuxtRouteMiddleware((route) => {
const { urlPrefix } = usePrefix()

const getPermissionRouteCondition = (cond: (value: string) => boolean, routeVisible: (value: Prefix) => boolean) => {
return {
cond,
replaceValue: () => {
if (!routeVisible(urlPrefix.value)) {
return '/'
}
},
}
}

let redirectValue

const paths = [
Expand All @@ -28,22 +40,18 @@ export default defineNuxtRouteMiddleware((route) => {
cond: val => val.includes('/rmrk2/'),
replaceValue: () => window.location.href.replace('/rmrk2/', '/ksm/'),
},
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/teleport`, teleportVisible),
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/transfer`, transferVisible),
getPermissionRouteCondition((val: string) => val === '/migrate', migrateVisible),
{
cond: val => val.startsWith('/transfer'),
replaceValue: () =>
window.location.href.replace('/transfer', '/ksm/transfer'),
},
{
cond: val =>
val === `/${urlPrefix.value}/create`
|| val === `/${urlPrefix.value}/massmint`
|| val.startsWith('/create'),
replaceValue: () => {
if (!createVisible(urlPrefix.value)) {
return '/'
}
},
},
getPermissionRouteCondition((val: string) =>
val === `/${urlPrefix.value}/create`
|| val === `/${urlPrefix.value}/massmint`
|| val.startsWith('/create'), createVisible),
]

for (const path of paths) {
Expand Down
4 changes: 3 additions & 1 deletion stores/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const useDropStore = defineStore('drop', {
mintedNFTs: [],
}
},
getters: {},
getters: {
getIsLoadingMaxCount: state => !(state.drop.minted >= 0 && Boolean(state.drop.max)),
},
actions: {
setLoading(payload: boolean) {
this.loading = payload
Expand Down
17 changes: 14 additions & 3 deletions utils/config/permission.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { chainPropListOf } from './chain.config'
import type { PartialConfig, Prefix } from './types'

const hasCreate: PartialConfig = {
Expand Down Expand Up @@ -32,7 +31,19 @@ export const createVisible = (prefix: Prefix | string): boolean => {
}

export const listVisible = (prefix: Prefix | string): boolean => {
return !isEvm(prefix as Prefix)
return isSub(prefix as Prefix)
}

export const transferVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const teleportVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const migrateVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const seriesInsightVisible = (prefix: Prefix | string) => {
Expand All @@ -48,7 +59,7 @@ export const salesVisible = (prefix: Prefix | string) => {
}

export const dropsVisible = (prefix: Prefix | string) => {
return prefix === 'ahk' || prefix === 'ahp' || chainPropListOf(prefix as Prefix).vm === 'EVM'
return prefix === 'ahk' || prefix === 'ahp' || isEvm(prefix)
}

export const explorerVisible = (prefix: Prefix | string): boolean => {
Expand Down
25 changes: 20 additions & 5 deletions utils/format/balance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { trimAll } from '@kodadot1/minimark/utils'
import type BN from 'bn.js'
import { formatBalance } from '@polkadot/util'
import type { Prefix } from '@kodadot1/static'

function format(
balance: number | string | BN | bigint,
Expand Down Expand Up @@ -83,7 +84,6 @@ export function roundTo(value: number | string, limit = 2) {
const hasDecimals = number % 1 !== 0
const fractionDigits = hasDecimals ? limit : 0
return number.toLocaleString(undefined, {
minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits,
})
}
Expand Down Expand Up @@ -113,12 +113,27 @@ const roundAmount = (
export const formatAmountWithRound = (
value: string | number | bigint,
tokenDecimals: number,
round?: number,
) =>
roundAmount(
roundBy?: number | Prefix,
) => {
let round: number | undefined
let roundByPrefix = false

if (typeof roundBy === 'string') {
const prefix = roundBy as Prefix
if (prefix && isEvm(prefix)) {
roundByPrefix = true
round = chainToPrecisionMap[prefixToChainMap[prefix]!]
}
}
else {
round = roundBy
}

return roundAmount(
format(checkInvalidBalanceFilter(value), tokenDecimals, ''),
round === 0 ? round : round || 4,
round === undefined,
roundByPrefix ? false : round === undefined,
)
}

export default format

0 comments on commit 82c92a0

Please sign in to comment.