Skip to content

Commit

Permalink
Fix empty balance from chain for contracts without state
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueCarry committed Jul 4, 2024
1 parent ee3cd0e commit c5f2504
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vite": "^5.2.11"
}
},
"packageManager": "pnpm@8.6.7+sha512.bd1216a43fcbe2985ff41936a3f3b64c347c7c5a099e962ba764caa9321917fa99dbfae02f7a8a5f31e87c781b5ec8a7c0ca12122833dbcb2a937a50fb230441"
}
6 changes: 3 additions & 3 deletions src/components/IndexPage/SessionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function SessionsList() {
className={'px-2'}
// className="cursor-pointer text-accent dark:text-accent-light"
onClick={async (e) => {
if (e.ctrlKey) {
if (e.ctrlKey || e.metaKey) {
e.preventDefault()
e.stopPropagation()
deleteTonConnectSession(s)
Expand All @@ -101,7 +101,7 @@ export function SessionsList() {
Your session will be deleted, and will disconnect from service
</AlertDialogDescription>
<AlertDialogDescription>
To close session without confirm popup use Ctrl + Click
To close session without confirm popup use Ctrl + Click or CMD + Click
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
Expand All @@ -125,7 +125,7 @@ export function SessionsList() {
</div>
<div className="flex">
<div>SubId:&nbsp;</div>
<div>{tonWallet?.subwalletId || 'Default'}</div>
<div>{tonWallet?.subwalletId.toString() || 'Default'}</div>
</div>
</div>

Expand Down
25 changes: 12 additions & 13 deletions src/hooks/useEmulatedTxInfo.ts

Large diffs are not rendered by default.

53 changes: 29 additions & 24 deletions src/store/tonConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,35 @@ export async function setTonConnectSessionAutoSend({
export async function deleteTonConnectSession(session: State<TonConnectSession>) {
// const session =

await sendTonConnectMessage(
{
event: 'disconnect',
payload: {},
id: Date.now(),
},
session?.secretKey.get() || Buffer.from(''),
session?.userId?.get() || ''
)

const db = await getDatabase()
await db<ConnectMessageTransaction>('connect_message_transactions')
.where({
connect_session_id: session.id.get(),
})
.delete()
await db<ConnectSession>('connect_sessions')
.where({
id: session.id.get(),
})
.delete()

state.sessions.set(await getSessions())
await removeConnectMessages()
try {
await sendTonConnectMessage(
{
event: 'disconnect',
payload: {},
id: Date.now(),
},
session?.secretKey.get() || Buffer.from(''),
session?.userId?.get() || ''
)

const db = await getDatabase()
await db<ConnectMessageTransaction>('connect_message_transactions')
.where({
connect_session_id: session.id.get(),
})
.delete()
await db<ConnectSession>('connect_sessions')
.where({
id: session.id.get(),
})
.delete()

state.sessions.set(await getSessions())
await removeConnectMessages()
} catch (e) {
console.log('Delete session error', e)
throw e
}
}

export async function updateSessionEventId(id: number, eventId: number) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/liteClientBlockchainStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class LiteClientBlockchainStorage implements BlockchainStorage {
!account.state.storage.state.state.code
) {
existing = SmartContract.empty(blockchain, address)
existing.balance = BigInt(account.balance.coins)
} else {
existing = SmartContract.create(blockchain, {
address,
Expand Down

0 comments on commit c5f2504

Please sign in to comment.