Skip to content

Commit 0d26cd8

Browse files
authored
Upgrade blockchain api (#1005)
1 parent 88b9f1f commit 0d26cd8

File tree

3 files changed

+26
-121
lines changed

3 files changed

+26
-121
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@helium/account-fetch-cache-hooks": "0.11.4",
3535
"@helium/address": "^5.0.4",
3636
"@helium/automation-hooks": "^0.11.4",
37-
"@helium/blockchain-api": "^0.2.4",
37+
"@helium/blockchain-api": "^0.3.2",
3838
"@helium/circuit-breaker-sdk": "0.11.4",
3939
"@helium/cron-sdk": "^0.0.8",
4040
"@helium/crypto-react-native": "^5.0.4",

src/hooks/useSubmitTxn.tsx

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AnchorProvider, Program } from '@coral-xyz/anchor'
12
import * as distributorOracle from '@helium/distributor-oracle'
23
import {
34
decodeEntityKey,
@@ -13,45 +14,43 @@ import {
1314
populateMissingDraftInfo,
1415
toVersionedTx,
1516
} from '@helium/spl-utils'
16-
import type { AnchorProvider, Program } from '@coral-xyz/anchor'
17-
import { getMint } from '@solana/spl-token'
1817
import { PublicKey, VersionedTransaction } from '@solana/web3.js'
1918
import { useAccountStorage } from '@storage/AccountStorageProvider'
19+
import { useMutation, useQueryClient } from '@tanstack/react-query'
20+
import { WrappedConnection } from '@utils/WrappedConnection'
21+
import { ellipsizeAddress } from '@utils/accountUtils'
2022
import {
2123
DAO_KEY,
2224
HNT_LAZY_KEY,
2325
IOT_LAZY_KEY,
24-
MOBILE_LAZY_KEY,
2526
MAX_TRANSACTIONS_PER_SIGNATURE_BATCH,
2627
Mints,
28+
MOBILE_LAZY_KEY,
2729
} from '@utils/constants'
28-
import { toAsset, getCachedKeyToAssets } from '@utils/solanaUtils'
29-
import { WrappedConnection } from '@utils/WrappedConnection'
30+
import { humanReadable } from '@utils/formatting'
3031
import i18n from '@utils/i18n'
3132
import * as solUtils from '@utils/solanaUtils'
33+
import { getCachedKeyToAssets, toAsset } from '@utils/solanaUtils'
3234
import BN from 'bn.js'
3335
import React, { useCallback } from 'react'
34-
import { ellipsizeAddress } from '@utils/accountUtils'
35-
import { humanReadable } from '@utils/formatting'
36-
import { useMutation, useQueryClient } from '@tanstack/react-query'
37-
import { SwapPreview } from '../solana/SwapPreview'
3836
import { CollectablePreview } from '../solana/CollectablePreview'
3937
import { MessagePreview } from '../solana/MessagePreview'
4038
import { PaymentPreivew } from '../solana/PaymentPreview'
4139
import { useSolana } from '../solana/SolanaProvider'
40+
import { SwapPreview } from '../solana/SwapPreview'
4241
import { useWalletSign } from '../solana/WalletSignProvider'
4342
import { WalletStandardMessageTypes } from '../solana/walletSignBottomSheetTypes'
4443
import { useBlockchainApi } from '../storage/BlockchainApiProvider'
45-
import {
46-
signTransactionData,
47-
toTransactionData,
48-
hashTagParams,
49-
} from '../utils/transactionUtils'
5044
import {
5145
Collectable,
5246
CompressedNFT,
5347
HotspotWithPendingRewards,
5448
} from '../types/solana'
49+
import {
50+
hashTagParams,
51+
signTransactionData,
52+
toTransactionData,
53+
} from '../utils/transactionUtils'
5554

5655
// Helper to get entityKey from a CompressedNFT
5756
async function getEntityKeyFromCompressedNFT(
@@ -145,30 +144,18 @@ export default () => {
145144
throw new Error(t('errors.account'))
146145
}
147146

148-
// Get mint decimals
149-
const mintInfo = await getMint(anchorProvider.connection, mint)
150-
151147
// For each payment, get transaction data from API
152148
const txnDataPromises = payments.map(async (payment) => {
153149
// Convert BN amount to decimal string
154150
const amountStr = payment.balanceAmount.toString()
155-
const paddedAmount =
156-
amountStr.length < mintInfo.decimals
157-
? amountStr.padStart(mintInfo.decimals, '0')
158-
: amountStr
159-
const integerPart =
160-
paddedAmount.length > mintInfo.decimals
161-
? paddedAmount.slice(0, paddedAmount.length - mintInfo.decimals)
162-
: '0'
163-
const decimalPart = paddedAmount.slice(-mintInfo.decimals)
164-
const decimalAmount = `${integerPart}.${decimalPart}`
165-
166151
const { transactionData } = await client.tokens.transfer({
152+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
167153
walletAddress: currentAccount.solanaAddress!,
168-
mint: mint.toBase58(),
154+
tokenAmount: {
155+
amount: amountStr,
156+
mint: mint.toBase58(),
157+
},
169158
destination: payment.payee,
170-
amount: decimalAmount,
171-
decimals: mintInfo.decimals,
172159
})
173160
return transactionData
174161
})

yarn.lock

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,15 +2533,13 @@ __metadata:
25332533
languageName: node
25342534
linkType: hard
25352535

2536-
"@helium/blockchain-api@npm:^0.2.4":
2537-
version: 0.2.4
2538-
resolution: "@helium/blockchain-api@npm:0.2.4"
2536+
"@helium/blockchain-api@npm:^0.3.2":
2537+
version: 0.3.2
2538+
resolution: "@helium/blockchain-api@npm:0.3.2"
25392539
dependencies:
2540-
"@orpc/client": "npm:^1.13.2"
25412540
"@orpc/contract": "npm:^1.13.2"
2542-
"@orpc/server": "npm:^1.13.2"
25432541
zod: "npm:^4.3.5"
2544-
checksum: 10/9851ce6c71946a44b778ec4e7bf2836bd9658368f70abb67e86e6a54aa53a045d56c6c9fa27b7023865a5179b203178f9ed639dbeabe2f9d11deeaba06dfd4db
2542+
checksum: 10/9dc9061a867c8a097dc4a734d44fb2cf0db3971de569649d7a62b0e42b9ac28539116446df49360bd6724280f46c419578dcfdf448346b3e1de2ec79d3f1396a
25452543
languageName: node
25462544
linkType: hard
25472545

@@ -4223,7 +4221,7 @@ __metadata:
42234221
languageName: node
42244222
linkType: hard
42254223

4226-
"@orpc/client@npm:1.13.4, @orpc/client@npm:^1.13.2":
4224+
"@orpc/client@npm:1.13.4":
42274225
version: 1.13.4
42284226
resolution: "@orpc/client@npm:1.13.4"
42294227
dependencies:
@@ -4235,7 +4233,7 @@ __metadata:
42354233
languageName: node
42364234
linkType: hard
42374235

4238-
"@orpc/contract@npm:1.13.4, @orpc/contract@npm:^1.13.2":
4236+
"@orpc/contract@npm:^1.13.2":
42394237
version: 1.13.4
42404238
resolution: "@orpc/contract@npm:1.13.4"
42414239
dependencies:
@@ -4247,40 +4245,6 @@ __metadata:
42474245
languageName: node
42484246
linkType: hard
42494247

4250-
"@orpc/interop@npm:1.13.4":
4251-
version: 1.13.4
4252-
resolution: "@orpc/interop@npm:1.13.4"
4253-
checksum: 10/58ee50a8b5322574816a7463ece6b4b90e0b49f05cfad846e326b9ba8d34d5b957f76cb0a2acbc55e2d079eb920199f8303afed28c693d265c18a9277ee9a2fb
4254-
languageName: node
4255-
linkType: hard
4256-
4257-
"@orpc/server@npm:^1.13.2":
4258-
version: 1.13.4
4259-
resolution: "@orpc/server@npm:1.13.4"
4260-
dependencies:
4261-
"@orpc/client": "npm:1.13.4"
4262-
"@orpc/contract": "npm:1.13.4"
4263-
"@orpc/interop": "npm:1.13.4"
4264-
"@orpc/shared": "npm:1.13.4"
4265-
"@orpc/standard-server": "npm:1.13.4"
4266-
"@orpc/standard-server-aws-lambda": "npm:1.13.4"
4267-
"@orpc/standard-server-fastify": "npm:1.13.4"
4268-
"@orpc/standard-server-fetch": "npm:1.13.4"
4269-
"@orpc/standard-server-node": "npm:1.13.4"
4270-
"@orpc/standard-server-peer": "npm:1.13.4"
4271-
cookie: "npm:^1.1.1"
4272-
peerDependencies:
4273-
crossws: ">=0.3.4"
4274-
ws: ">=8.18.1"
4275-
peerDependenciesMeta:
4276-
crossws:
4277-
optional: true
4278-
ws:
4279-
optional: true
4280-
checksum: 10/fe86117c240290efec518b42791b181c7d6498eba9e46a85878e9b9262dffcd4877db6c1fd9341588aa8f2dd636f67b6ad770c16526c29627950bd34666a17f6
4281-
languageName: node
4282-
linkType: hard
4283-
42844248
"@orpc/shared@npm:1.13.4":
42854249
version: 1.13.4
42864250
resolution: "@orpc/shared@npm:1.13.4"
@@ -4296,34 +4260,6 @@ __metadata:
42964260
languageName: node
42974261
linkType: hard
42984262

4299-
"@orpc/standard-server-aws-lambda@npm:1.13.4":
4300-
version: 1.13.4
4301-
resolution: "@orpc/standard-server-aws-lambda@npm:1.13.4"
4302-
dependencies:
4303-
"@orpc/shared": "npm:1.13.4"
4304-
"@orpc/standard-server": "npm:1.13.4"
4305-
"@orpc/standard-server-fetch": "npm:1.13.4"
4306-
"@orpc/standard-server-node": "npm:1.13.4"
4307-
checksum: 10/8532c591068dc12ca6b6df009fbecb3d7cc0b36f734c2888b336dc563f581f47b88b338b00d62983f4cb89f489773260d41a9c40c9c4a49f8abda8ba01e59ecf
4308-
languageName: node
4309-
linkType: hard
4310-
4311-
"@orpc/standard-server-fastify@npm:1.13.4":
4312-
version: 1.13.4
4313-
resolution: "@orpc/standard-server-fastify@npm:1.13.4"
4314-
dependencies:
4315-
"@orpc/shared": "npm:1.13.4"
4316-
"@orpc/standard-server": "npm:1.13.4"
4317-
"@orpc/standard-server-node": "npm:1.13.4"
4318-
peerDependencies:
4319-
fastify: ">=5.6.1"
4320-
peerDependenciesMeta:
4321-
fastify:
4322-
optional: true
4323-
checksum: 10/b2c7cd995a4f6cdc52013dba30988ca9704a97ecd000acc06af73b24ba96f7929244af266c3c81588a8bbad555968b943640c4ef35306e7d183d17f97562d901
4324-
languageName: node
4325-
linkType: hard
4326-
43274263
"@orpc/standard-server-fetch@npm:1.13.4":
43284264
version: 1.13.4
43294265
resolution: "@orpc/standard-server-fetch@npm:1.13.4"
@@ -4334,17 +4270,6 @@ __metadata:
43344270
languageName: node
43354271
linkType: hard
43364272

4337-
"@orpc/standard-server-node@npm:1.13.4":
4338-
version: 1.13.4
4339-
resolution: "@orpc/standard-server-node@npm:1.13.4"
4340-
dependencies:
4341-
"@orpc/shared": "npm:1.13.4"
4342-
"@orpc/standard-server": "npm:1.13.4"
4343-
"@orpc/standard-server-fetch": "npm:1.13.4"
4344-
checksum: 10/70c69fd4cb9f567427e5d269614a87a7b288744ba287cc73a52060db4ee9a2c6335cfd474bb0737ff6c4b857112af6e71c450548e7833f31c5d8ce848b7ebc9e
4345-
languageName: node
4346-
linkType: hard
4347-
43484273
"@orpc/standard-server-peer@npm:1.13.4":
43494274
version: 1.13.4
43504275
resolution: "@orpc/standard-server-peer@npm:1.13.4"
@@ -9585,13 +9510,6 @@ __metadata:
95859510
languageName: node
95869511
linkType: hard
95879512

9588-
"cookie@npm:^1.1.1":
9589-
version: 1.1.1
9590-
resolution: "cookie@npm:1.1.1"
9591-
checksum: 10/85538153054791155cf4d38d2e807e3b9382d71bf71d92fc46fca348515ea574049d0d9ef8eb84d2d54a681ad1d7a7316b1989b901dace50a6c0f4c3858dbdb2
9592-
languageName: node
9593-
linkType: hard
9594-
95959513
"copy-descriptor@npm:^0.1.0":
95969514
version: 0.1.1
95979515
resolution: "copy-descriptor@npm:0.1.1"
@@ -12678,7 +12596,7 @@ __metadata:
1267812596
"@helium/account-fetch-cache-hooks": "npm:0.11.4"
1267912597
"@helium/address": "npm:^5.0.4"
1268012598
"@helium/automation-hooks": "npm:^0.11.4"
12681-
"@helium/blockchain-api": "npm:^0.2.4"
12599+
"@helium/blockchain-api": "npm:^0.3.2"
1268212600
"@helium/circuit-breaker-sdk": "npm:0.11.4"
1268312601
"@helium/cron-sdk": "npm:^0.0.8"
1268412602
"@helium/crypto-react-native": "npm:^5.0.4"

0 commit comments

Comments
 (0)