generated from ton-community/twa-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
675b3ac
commit 2db3d09
Showing
6 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
Contract, | ||
ContractProvider, | ||
Sender, | ||
Address, | ||
Cell, | ||
contractAddress, | ||
beginCell, | ||
toNano, | ||
} from "ton-core"; | ||
|
||
interface Order { | ||
id: number; | ||
details: string; | ||
status: boolean; | ||
} | ||
|
||
export default class ShopContract implements Contract { | ||
async sendMessage( | ||
provider: ContractProvider, | ||
via: Sender, | ||
message: Cell | ||
) { | ||
await provider.internal(via, { | ||
value: toNano("0.05"), | ||
body: message, | ||
}); | ||
} | ||
|
||
async getWalletAddress(provider: ContractProvider, forAddress: Address) { | ||
const { stack } = await provider.get("get_wallet_address", [ | ||
{ type: "slice", cell: beginCell().storeAddress(forAddress).endCell() }, | ||
]); | ||
|
||
return stack.readAddress().toString(); | ||
} | ||
|
||
constructor( | ||
readonly address: Address, | ||
readonly init?: { code: Cell; data: Cell } | ||
) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useState } from "react"; | ||
import Counter from "../contracts/counter"; | ||
import { useTonClient } from "./useTonClient"; | ||
import { useAsyncInitialize } from "./useAsyncInitialize"; | ||
import { useTonConnect } from "./useTonConnect"; | ||
import { Address, OpenedContract } from "ton-core"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { CHAIN } from "@tonconnect/protocol"; | ||
|
||
export function useCBDShopContract() { | ||
const { client } = useTonClient(); | ||
const { sender, network } = useTonConnect(); | ||
|
||
const counterContract = useAsyncInitialize(async () => { | ||
if (!client) return; | ||
const contract = new Counter( | ||
Address.parse( | ||
network === CHAIN.MAINNET | ||
? "EQBPEDbGdwaLv1DKntg9r6SjFIVplSaSJoJ-TVLe_2rqBOmH" | ||
: "EQBYLTm4nsvoqJRvs_L-IGNKwWs5RKe19HBK_lFadf19FUfb" | ||
) // replace with your address from tutorial 2 step 8 | ||
); | ||
return client.open(contract) as OpenedContract<Counter>; | ||
}, [client]); | ||
|
||
const { data, isFetching } = useQuery( | ||
["counter"], | ||
async () => { | ||
if (!counterContract) return null; | ||
return (await counterContract!.getCounter()).toString(); | ||
}, | ||
{ refetchInterval: 3000 } | ||
); | ||
|
||
return { | ||
value: isFetching ? null : data, | ||
address: counterContract?.address.toString(), | ||
sendIncrement: () => { | ||
return counterContract?.sendIncrement(sender); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters