Skip to content

Commit

Permalink
feat: Add CAT721
Browse files Browse the repository at this point in the history
fix: Missing "key" prop for element in iterator

fix some type error.
update Cat721CollectionScreen.
motify Cat20 -> CAT20.

fix: Reverse

fix

feat: Add the feature to purchase FB.

fix

Revert "feat: Add the feature to purchase FB."

This reverts commit 2870ff939404c6ed01c3840d9bbfaf0edbf7415b.
  • Loading branch information
slient-coder committed Jan 10, 2025
1 parent 92bc587 commit 391caac
Show file tree
Hide file tree
Showing 36 changed files with 1,301 additions and 56 deletions.
13 changes: 13 additions & 0 deletions build/_raw/images/icons/fb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 96 additions & 7 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
import { contactBookService, keyringService, notificationService, openapiService, permissionService, preferenceService, sessionService } from '@/background/service';
import {
contactBookService,
keyringService,
notificationService,
openapiService,
permissionService,
preferenceService,
sessionService
} from '@/background/service';
import i18n from '@/background/service/i18n';
import { DisplayedKeyring, Keyring } from '@/background/service/keyring';
import { ADDRESS_TYPES, AddressFlagType, AUTO_LOCKTIMES, BRAND_ALIAN_TYPE_TEXT, CHAINS_ENUM, CHAINS_MAP, ChainType, COIN_NAME, COIN_SYMBOL, DEFAULT_LOCKTIME_ID, EVENTS, KEYRING_TYPE, KEYRING_TYPES, NETWORK_TYPES, UNCONFIRMED_HEIGHT } from '@/shared/constant';
import {
ADDRESS_TYPES,
AddressFlagType,
AUTO_LOCKTIMES,
BRAND_ALIAN_TYPE_TEXT,
CHAINS_ENUM,
CHAINS_MAP,
ChainType,
COIN_NAME,
COIN_SYMBOL,
DEFAULT_LOCKTIME_ID,
EVENTS,
KEYRING_TYPE,
KEYRING_TYPES,
NETWORK_TYPES,
UNCONFIRMED_HEIGHT
} from '@/shared/constant';
import eventBus from '@/shared/eventBus';
import { runesUtils } from '@/shared/lib/runes-utils';
import { Account, AddressType, AddressUserToSignInput, BitcoinBalance, NetworkType, PublicKeyUserToSignInput, SignPsbtOptions, ToSignInput, UTXO, WalletKeyring } from '@/shared/types';
import {
Account,
AddressType,
AddressUserToSignInput,
BitcoinBalance,
NetworkType,
PublicKeyUserToSignInput,
SignPsbtOptions,
ToSignInput,
UTXO,
WalletKeyring
} from '@/shared/types';
import { checkAddressFlag, getChainInfo } from '@/shared/utils';
import { txHelpers, UnspentOutput, UTXO_DUST } from '@unisat/wallet-sdk';
import { isValidAddress, publicKeyToAddress, scriptPkToAddress } from '@unisat/wallet-sdk/lib/address';
import { bitcoin, ECPair } from '@unisat/wallet-sdk/lib/bitcoin-core';
import { KeystoneKeyring } from '@unisat/wallet-sdk/lib/keyring';
import { genPsbtOfBIP322Simple, getSignatureFromPsbtOfBIP322Simple, signMessageOfBIP322Simple } from '@unisat/wallet-sdk/lib/message';
import {
genPsbtOfBIP322Simple,
getSignatureFromPsbtOfBIP322Simple,
signMessageOfBIP322Simple
} from '@unisat/wallet-sdk/lib/message';
import { toPsbtNetwork } from '@unisat/wallet-sdk/lib/network';
import { getAddressUtxoDust } from '@unisat/wallet-sdk/lib/transaction';
import { toXOnly } from '@unisat/wallet-sdk/lib/utils';



import { ContactBookItem } from '../service/contactBook';
import { OpenApiService } from '../service/openapi';
import { ConnectedSite } from '../service/permission';
import BaseController from './base';


const stashKeyrings: Record<string, Keyring> = {};
export type AccountAsset = {
name: string;
Expand Down Expand Up @@ -2090,6 +2126,59 @@ export class WalletController extends BaseController {
getBlockActiveInfo = () => {
return openapiService.getBlockActiveInfo();
};

getCAT721List = async (address: string, currentPage: number, pageSize: number) => {
const cursor = (currentPage - 1) * pageSize;
const size = pageSize;
const { total, list } = await openapiService.getCAT721CollectionList(address, cursor, size);

return {
currentPage,
pageSize,
total,
list
};
};

getAddressCAT721CollectionSummary = async (address: string, collectionId: string) => {
const collectionSummary = await openapiService.getAddressCAT721CollectionSummary(address, collectionId);
return collectionSummary;
};

transferCAT721Step1 = async (to: string, collectionId: string, localId: string, feeRate: number) => {
const currentAccount = await this.getCurrentAccount();
if (!currentAccount) {
return;
}

const _res = await openapiService.transferCAT721Step1(
currentAccount.address,
currentAccount.pubkey,
to,
collectionId,
localId,
feeRate
);
return _res;
};

transferCAT721Step2 = async (transferId: string, commitTx: string, toSignInputs: ToSignInput[]) => {
const networkType = this.getNetworkType();
const psbtNetwork = toPsbtNetwork(networkType);
const psbt = bitcoin.Psbt.fromBase64(commitTx, { network: psbtNetwork });
await this.signPsbt(psbt, toSignInputs, true);
const _res = await openapiService.transferCAT721Step2(transferId, psbt.toBase64());
return _res;
};

transferCAT721Step3 = async (transferId: string, revealTx: string, toSignInputs: ToSignInput[]) => {
const networkType = this.getNetworkType();
const psbtNetwork = toPsbtNetwork(networkType);
const psbt = bitcoin.Psbt.fromBase64(revealTx, { network: psbtNetwork });
await this.signPsbt(psbt, toSignInputs, false);
const _res = await openapiService.transferCAT721Step3(transferId, psbt.toBase64());
return _res;
};
}

export default new WalletController();
75 changes: 69 additions & 6 deletions src/background/service/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import randomstring from 'randomstring';



import { createPersistStore } from '@/background/utils';
import { CHAINS_MAP, CHANNEL, VERSION } from '@/shared/constant';
import { AddressRunesTokenSummary, AddressSummary, AddressTokenSummary, AppInfo, AppSummary, Arc20Balance, BitcoinBalance, CAT20Balance, CoinPrice, DecodedPsbt, FeeSummary, InscribeOrder, Inscription, InscriptionSummary, RuneBalance, TickPriceItem, TokenBalance, TokenTransfer, UTXO, UTXO_Detail, VersionDetail, WalletConfig } from '@/shared/types';


import {
AddressRunesTokenSummary,
AddressSummary,
AddressTokenSummary,
AppInfo,
AppSummary,
Arc20Balance,
BitcoinBalance,
CAT20Balance,
CAT721CollectionInfo,
CoinPrice,
DecodedPsbt,
FeeSummary,
InscribeOrder,
Inscription,
InscriptionSummary,
RuneBalance,
TickPriceItem,
TokenBalance,
TokenTransfer,
UTXO,
UTXO_Detail,
VersionDetail,
WalletConfig
} from '@/shared/types';

import { preferenceService } from '.';


interface OpenApiStore {
deviceId: string;
config?: WalletConfig;
Expand Down Expand Up @@ -637,6 +656,50 @@ export class OpenApiService {
id: mergeId
});
}

async getCAT721CollectionList(
address: string,
cursor: number,
size: number
): Promise<{ list: CAT721CollectionInfo[]; total: number }> {
return this.httpGet('/v5/cat721/collection/list', { address, cursor, size });
}

async getAddressCAT721CollectionSummary(address: string, collectionId: string) {
return this.httpGet(`/v5/cat721/collection-summary?address=${address}&collectionId=${collectionId}`, {});
}

async transferCAT721Step1(
address: string,
pubkey: string,
to: string,
collectionId: string,
localId: string,
feeRate: number
) {
return this.httpPost(`/v5/cat721/transfer-nft-step1`, {
address,
pubkey,
to,
collectionId,
localId,
feeRate
});
}

async transferCAT721Step2(transferId: string, signedPsbt: string) {
return this.httpPost(`/v5/cat721/transfer-nft-step2`, {
id: transferId,
psbt: signedPsbt
});
}

async transferCAT721Step3(transferId: string, signedPsbt: string) {
return this.httpPost(`/v5/cat721/transfer-nft-step3`, {
id: transferId,
psbt: signedPsbt
});
}
}

export default new OpenApiService();
21 changes: 21 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,24 @@ export interface WebsiteResult {
warning: string;
allowQuickMultiSign: boolean;
}

export interface CAT721Balance {
collectionId: string;
name: string;
count: number;
previewLocalIds: string[];
}

export interface CAT721CollectionInfo {
collectionId: string;
name: string;
symbol: string;
max: string;
premine: string;
description: string;
}

export interface AddressCAT721CollectionSummary {
collectionInfo: CAT721CollectionInfo;
localIds: string[];
}
16 changes: 15 additions & 1 deletion src/ui/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface ButtonProps {
children?: React.ReactNode;
onClick?: React.MouseEventHandler<HTMLDivElement>;
icon?: IconTypes;
iconSize?: {
width: number;
height: number;
};
disabled?: boolean;
full?: boolean;
}
Expand Down Expand Up @@ -210,6 +214,7 @@ export function Button(props: ButtonProps) {
LeftAccessory,
onClick,
icon,
iconSize,
disabled,
full,
...rest
Expand Down Expand Up @@ -262,7 +267,16 @@ export function Button(props: ButtonProps) {
onClick={disabled ? undefined : onClick}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}>
{icon && <Icon icon={icon} style={{ marginRight: spacing.tiny, backgroundColor: colors.white }} />}
{icon && (
<Icon
icon={icon}
style={Object.assign(
{ marginRight: spacing.tiny, backgroundColor: colors.white },
iconSize ? iconSize : {}
)}
containerStyle={iconSize ? iconSize : {}}
/>
)}
{text && <Text style={$textStyle} text={text} preset="regular" mt="sm" />}
</div>
);
Expand Down
Loading

0 comments on commit 391caac

Please sign in to comment.