Skip to content

Commit

Permalink
fix(tezos-fa-form): check for undefined metadata before extracting FA…
Browse files Browse the repository at this point in the history
… interface
  • Loading branch information
jsamol authored and 7alip committed Nov 19, 2021
1 parent 13f80bb commit b067d77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/app/components/tezos-fa-form/tezos-fa-form.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export class TezosFAFormStore extends ComponentStore<TezosFAFormState> {
})

private updateWithError = this.updater((state: TezosFAFormState, error: unknown) => {
const tezosFAFormError = isTezosFAFormError(error) ? error : unknownError()
const tezosFAFormError = isTezosFAFormError(error) ? error : unknownError(error)

if (tezosFAFormError.type === TezosFAFormErrorType.UNKNOWN && tezosFAFormError.error) {
console.error(error)
}

return {
...state,
Expand Down Expand Up @@ -253,6 +257,10 @@ export class TezosFAFormStore extends ComponentStore<TezosFAFormState> {
private async getTokenInterface(contract: TezosContract, tokenInterface?: TokenInterface): Promise<TokenInterface | undefined> {
if (!tokenInterface) {
const metadata = await this.getContractMetadata(contract)
if (!metadata) {
return undefined
}

if (hasTokenInterface(metadata, TokenInterface.FA1p2)) {
return TokenInterface.FA1p2
} else if (hasTokenInterface(metadata, TokenInterface.FA2)) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/tezos-fa-form/tezos-fa-form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export interface ContractNotFoundError extends TezosFAFormBaseError<TezosFAFormE
export interface InterfaceUnknownError extends TezosFAFormBaseError<TezosFAFormErrorType.INTERFACE_UNKNOWN> { tokenInterfaces: TokenInterface[] }
export interface TokenMetadataMissingError extends TezosFAFormBaseError<TezosFAFormErrorType.TOKEN_METADATA_MISSING> {}
export interface TokenVagueError extends TezosFAFormBaseError<TezosFAFormErrorType.TOKEN_VAGUE> { tokens: TokenDetails[] }
export interface UnknownError extends TezosFAFormBaseError<TezosFAFormErrorType.UNKNOWN> {}
export interface UnknownError extends TezosFAFormBaseError<TezosFAFormErrorType.UNKNOWN> {
error?: any
}

export type TezosFAFormError =
| ContractNotFoundError
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/tezos-fa-form/tezos-fa-form.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function tokenVaugeError(tokenMetadataRegistry: Record<number, TezosFATok
return { type: TezosFAFormErrorType.TOKEN_VAGUE, tokens }
}

export function unknownError(): UnknownError {
return { type: TezosFAFormErrorType.UNKNOWN }
export function unknownError(error?: any): UnknownError {
return { type: TezosFAFormErrorType.UNKNOWN, error }
}

export function isTezosFAFormError(error: unknown): error is TezosFAFormError {
Expand Down

0 comments on commit b067d77

Please sign in to comment.