Skip to content

Commit

Permalink
Add smart rollup address support
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Oct 31, 2024
1 parent e7b81b3 commit f20a52e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src/components/AddressPill/AddressPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const AddressPill = memo(
showIcons,
addressKind,
addressAlias,
address,
onClick,
elementRef,
isMouseHover,
Expand Down Expand Up @@ -109,7 +110,7 @@ export const AddressPill = memo(
</PopoverBody>
</PopoverContent>
</Popover>
{showIcons && (
{showIcons && address.type !== "smart_rollup" && (
<RightIcon
marginRight="4px"
stroke={colors.gray[300]}
Expand Down
19 changes: 18 additions & 1 deletion packages/tezos/src/Address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ValidationResult, validateAddress } from "@taquito/utils";

import { type Address, type ContractAddress, type ImplicitAddress } from "./types";
import {

Check failure on line 3 in packages/tezos/src/Address.ts

View workflow job for this annotation

GitHub Actions / test

All imports in the declaration are only used as types. Use `import type`
SmartRollupAddress,
type Address,

Check warning on line 5 in packages/tezos/src/Address.ts

View workflow job for this annotation

GitHub Actions / test

Member 'Address' of the import declaration should be sorted alphabetically
type ContractAddress,
type ImplicitAddress,
} from "./types";

export const parsePkh = (pkh: string): Address => {
if (isValidContractPkh(pkh)) {
Expand All @@ -9,6 +14,9 @@ export const parsePkh = (pkh: string): Address => {
if (isValidImplicitPkh(pkh)) {
return parseImplicitPkh(pkh);
}
if (isValidSmartRollupPkh(pkh)) {
return parseSmartRollupPkh(pkh);
}
throw new Error(`Cannot parse address type: ${pkh}`);
};

Expand All @@ -18,6 +26,8 @@ export const isValidContractPkh = (pkh: string) => isAddressValid(pkh) && pkh.ma

export const isValidImplicitPkh = (pkh: string) => isAddressValid(pkh) && pkh.match(/^tz[1234]\w+/);

export const isValidSmartRollupPkh = (pkh: string) => isAddressValid(pkh) && pkh.match(/^sr1\w+/);

export const parseContractPkh = (pkh: string): ContractAddress => {
if (isValidContractPkh(pkh)) {
return { type: "contract", pkh };
Expand All @@ -31,3 +41,10 @@ export const parseImplicitPkh = (pkh: string): ImplicitAddress => {
}
throw new Error(`Invalid implicit address: ${pkh}`);
};

export const parseSmartRollupPkh = (pkh: string): SmartRollupAddress => {
if (isValidSmartRollupPkh(pkh)) {
return { type: "smart_rollup", pkh };
}
throw new Error(`Invalid smart rollup address: ${pkh}`);
};
7 changes: 6 additions & 1 deletion packages/tezos/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type ImplicitAddress = {
pkh: RawPkh;
};

export type Address = ContractAddress | ImplicitAddress;
export type SmartRollupAddress = {
type: "smart_rollup";
pkh: RawPkh;
};

export type Address = ContractAddress | ImplicitAddress | SmartRollupAddress;

export type Estimation = {
storageLimit: number;
Expand Down

0 comments on commit f20a52e

Please sign in to comment.