Skip to content

Commit

Permalink
fix: asset opt-out and add/edit app interface with arc56
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Jan 28, 2025
1 parent e2ee182 commit 8fdb025
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
17 changes: 12 additions & 5 deletions src/features/app-interfaces/components/edit/add-app-spec-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { AppSpecStandard, AppSpecVersion, Arc32AppSpec, Arc4AppSpec } from '../.
import { useAddAppSpecVersion } from '../../data/update'
import { ApplicationId } from '@/features/applications/data/types'
import { parseAsAppSpec } from '../../mappers'
import { isArc32AppSpec, isArc4AppSpec } from '@/features/common/utils'
import { isArc32AppSpec, isArc4AppSpec, isArc56AppSpec } from '@/features/common/utils'
import { invariant } from '@/utils/invariant'
import { AppSpecFormInner, appSpecSchema, supportedStandards } from './app-spec-form-inner'
import { toast } from 'react-toastify'
import { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56'

type Props = {
applicationId: ApplicationId
Expand All @@ -34,13 +35,19 @@ export function AddAppSpecForm({ applicationId, onSuccess }: Props) {
appSpec: parsedAppSpec as Arc32AppSpec,
standard: AppSpecStandard.ARC32,
} satisfies AppSpecVersion)
: isArc4AppSpec(parsedAppSpec)
: isArc56AppSpec(parsedAppSpec)
? ({
...common,
appSpec: parsedAppSpec as Arc4AppSpec,
standard: AppSpecStandard.ARC4,
appSpec: parsedAppSpec as Arc56Contract,
standard: AppSpecStandard.ARC56,
} satisfies AppSpecVersion)
: undefined
: isArc4AppSpec(parsedAppSpec)
? ({
...common,
appSpec: parsedAppSpec as Arc4AppSpec,
standard: AppSpecStandard.ARC4,
} satisfies AppSpecVersion)
: undefined

invariant(appSpecVersion, 'App spec standard is not supported')
await addAppSpecVersion(applicationId, appSpecVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FormInnerProps = {
helper: FormFieldHelper<z.infer<typeof appSpecSchema>>
}

export const supportedStandards = [AppSpecStandard.ARC32, AppSpecStandard.ARC4]
export const supportedStandards = [AppSpecStandard.ARC56, AppSpecStandard.ARC32, AppSpecStandard.ARC4]

export function AppSpecFormInner({ helper }: FormInnerProps) {
return (
Expand Down
17 changes: 12 additions & 5 deletions src/features/app-interfaces/components/edit/edit-app-spec-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { AppSpecStandard, AppSpecVersion, Arc32AppSpec, Arc4AppSpec } from '../.
import { useUpdateAppSpecVersion } from '../../data/update'
import { ApplicationId } from '@/features/applications/data/types'
import { asAppSpecFilename, parseAsAppSpec } from '../../mappers'
import { isArc32AppSpec, isArc4AppSpec } from '@/features/common/utils'
import { isArc32AppSpec, isArc4AppSpec, isArc56AppSpec } from '@/features/common/utils'
import { invariant } from '@/utils/invariant'
import { AppSpecFormInner, appSpecSchema, supportedStandards } from './app-spec-form-inner'
import { asJson } from '@/utils/as-json'
import { toast } from 'react-toastify'
import { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56'

type Props = {
applicationId: ApplicationId
Expand All @@ -37,13 +38,19 @@ export function EditAppSpecForm({ applicationId, appSpecIndex, appSpec, onSucces
appSpec: parsedAppSpec as Arc32AppSpec,
standard: AppSpecStandard.ARC32,
} satisfies AppSpecVersion)
: isArc4AppSpec(parsedAppSpec)
: isArc56AppSpec(parsedAppSpec)
? ({
...common,
appSpec: parsedAppSpec as Arc4AppSpec,
standard: AppSpecStandard.ARC4,
appSpec: parsedAppSpec as Arc56Contract,
standard: AppSpecStandard.ARC56,
} satisfies AppSpecVersion)
: undefined
: isArc4AppSpec(parsedAppSpec)
? ({
...common,
appSpec: parsedAppSpec as Arc4AppSpec,
standard: AppSpecStandard.ARC4,
} satisfies AppSpecVersion)
: undefined

invariant(appSpecVersion, 'App spec standard is not supported')
await updateAppSpecVersion(applicationId, appSpecIndex, appSpecVersion)
Expand Down
2 changes: 1 addition & 1 deletion src/features/assets/data/asset-opt-in-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useAssetOptInOut = (asset: Asset) => {
return {
hasActiveAccount: !!activeAccount,
canOptIn: !activeAccount.assetHolding.has(asset.id),
canOptOut: activeAccount.assetHolding.has(asset.id) && activeAccount.assetHolding.get(asset.id)!.amount === 0,
canOptOut: activeAccount.assetHolding.has(asset.id) && activeAccount.assetHolding.get(asset.id)!.amount === 0n,
}
})
}, [asset])
Expand Down
4 changes: 2 additions & 2 deletions src/features/fund/data/dispenser-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ const createRefundStatusAtom = () => {
return atom(async (get) => {
const activeAccount = await get(activeWalletAccountAtom)
// approxLimit = balance - minBalance - likelyTransactionFee
const approxLimit = Number(activeAccount?.algoHolding.amount ?? 0) - (activeAccount?.minBalance ?? 0) - 1000
const approxLimit = (activeAccount?.algoHolding.amount ?? 0n) - (activeAccount?.minBalance ?? 0n) - 1000n

return {
canRefund: !!activeAccount,
limit: microAlgos(approxLimit < 0 ? 0 : approxLimit),
limit: microAlgos(approxLimit < 0n ? 0n : approxLimit),
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/wallet/data/active-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const getActiveWalletAccount = async (address: string) => {
algoHolding: {
amount: accountInformation.balance.microAlgo,
},
minBalance: Number(accountInformation.minBalance.microAlgo),
validAtRound: Number(accountInformation.validAsOfRound),
minBalance: accountInformation.minBalance.microAlgo,
validAtRound: accountInformation.validAsOfRound,
} satisfies Omit<ActiveWalletAccount, 'nfd'>
}

Expand Down
6 changes: 3 additions & 3 deletions src/features/wallet/types/active-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export type ActiveWalletAccount = {
address: Address
assetHolding: Map<AssetId, AccountAssetHolding>
algoHolding: AccountAssetHolding
minBalance: number
validAtRound: number
minBalance: bigint
validAtRound: bigint
nfd: Nfd | null
}

type AccountAssetHolding = {
amount: number | bigint
amount: bigint
}

0 comments on commit 8fdb025

Please sign in to comment.