Skip to content

Commit

Permalink
Add address field to getData methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
barinbritva committed Feb 7, 2024
1 parent bbd7e8d commit 9d6d92a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing

## Developing process

```sh
# do a local build
npm install
npm run dev --workspace=@ton/phaser-sdk

# link the package
cd ./packages/phaser
npm link

# in a consumer project
npm link @ton/phaser-sdk
```
12 changes: 10 additions & 2 deletions packages/common/jetton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export interface JettonTransferRequest {
forwardMessage?: string;
}

export interface JettonMinter extends DomainJettonMinter {}
export interface JettonMinter extends DomainJettonMinter {
address: Address;
}

export class JettonManager {
private readonly manager: DomainJettonManager;
Expand All @@ -94,7 +96,13 @@ export class JettonManager {
}

public async getData(address: Address | string): Promise<JettonMinter> {
return this.manager.getData(AddressUtils.toObject(address));
const addressObject = AddressUtils.toObject(address);
const domainData = await this.manager.getData(addressObject);

return {
...domainData,
address: addressObject
};
}

public async transfer({
Expand Down
12 changes: 6 additions & 6 deletions packages/common/nft-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ export interface DomainNftCollection {
export class DomainNftCollectionManager {
constructor(private readonly tonClient: TonClient) {}

public async getData(address: Address | string): Promise<DomainNftCollection> {
const {stack} = await this.tonClient.runMethod(
typeof address === 'string' ? Address.parse(address) : address,
'get_collection_data'
);
public async getData(address: Address): Promise<DomainNftCollection> {
const {stack} = await this.tonClient.runMethod(address, 'get_collection_data');

return {
nextItemIndex: stack.readBigNumber(),
Expand Down Expand Up @@ -59,6 +56,7 @@ export class DomainNftCollectionManager {
/** Client specific */

export interface NftCollection {
address: Address;
nextItemIndex: bigint;
content: NftContent;
owner: Address | null;
Expand All @@ -75,9 +73,11 @@ export class NftCollectionManager {
}

public async getData(address: Address | string): Promise<NftCollection> {
const domainData = await this.domainManager.getData(address);
const addressObject = AddressUtils.toObject(address);
const domainData = await this.domainManager.getData(addressObject);

return {
address: addressObject,
nextItemIndex: domainData.nextItemIndex,
content: parseNftContent(await loadFullContent(domainData.content, this.contentResolver)),
owner: domainData.owner
Expand Down
12 changes: 6 additions & 6 deletions packages/common/nft-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export class DomainNftItemManager {
this.collectionManager = new DomainNftCollectionManager(this.tonClient);
}

public async getData(address: Address | string): Promise<DomainNftItem> {
const {stack} = await this.tonClient.runMethod(
typeof address === 'string' ? Address.parse(address) : address,
'get_nft_data'
);
public async getData(address: Address): Promise<DomainNftItem> {
const {stack} = await this.tonClient.runMethod(address, 'get_nft_data');

const data: DomainNftItem = {
initialized: stack.readBoolean(),
Expand Down Expand Up @@ -85,6 +82,7 @@ export class DomainNftItemManager {
export interface Nft {
initialized: boolean;
index: bigint;
address: Address;
collection: Address | null;
owner: Address | null;
content: NftContent | null;
Expand Down Expand Up @@ -112,11 +110,13 @@ export class NftItemManager {
}

public async getData(address: Address | string): Promise<Nft> {
const domainData = await this.manager.getData(address);
const addressObject = AddressUtils.toObject(address);
const domainData = await this.manager.getData(addressObject);

return {
initialized: domainData.initialized,
index: domainData.index,
address: addressObject,
collection: domainData.collection,
owner: domainData.owner,
content:
Expand Down

0 comments on commit 9d6d92a

Please sign in to comment.