Skip to content

Commit

Permalink
Fix NEAR implementation after the NAJ update.
Browse files Browse the repository at this point in the history
  • Loading branch information
kujtimprenku committed Sep 9, 2024
1 parent 1bf20a4 commit be30acc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
16 changes: 12 additions & 4 deletions advanced/wallets/react-wallet-v2/src/lib/NearLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export class NearWallet {
chainId,
transactions
}: CreateTransactionsParams): Promise<Array<nearTransactions.Transaction>> {
const provider = new providers.JsonRpcProvider(NEAR_TEST_CHAINS[chainId as TNearChain].rpc)
const provider = new providers.JsonRpcProvider({
url: NEAR_TEST_CHAINS[chainId as TNearChain].rpc
})
const txs: Array<nearTransactions.Transaction> = []

const [block, accounts] = await Promise.all([
Expand All @@ -227,12 +229,14 @@ export class NearWallet {
public_key: account.publicKey
})

const nonce = BigInt(accessKey.nonce) + BigInt(i) + 1n

txs.push(
nearTransactions.createTransaction(
transaction.signerId,
utils.PublicKey.from(account.publicKey),
transaction.receiverId,
accessKey.nonce + i + 1,
nonce,
transaction.actions,
utils.serialize.base_decode(block.header.hash)
)
Expand Down Expand Up @@ -368,7 +372,9 @@ export class NearWallet {
topic,
transaction
}: SignAndSendTransactionParams): Promise<providers.FinalExecutionOutcome> {
const provider = new providers.JsonRpcProvider(NEAR_TEST_CHAINS[chainId as TNearChain].rpc)
const provider = new providers.JsonRpcProvider({
url: NEAR_TEST_CHAINS[chainId as TNearChain].rpc
})
const [signedTx] = await this.signTransactions({
chainId,
topic,
Expand All @@ -383,7 +389,9 @@ export class NearWallet {
topic,
transactions
}: SignAndSendTransactionsParams): Promise<Array<providers.FinalExecutionOutcome>> {
const provider = new providers.JsonRpcProvider(NEAR_TEST_CHAINS[chainId as TNearChain].rpc)
const provider = new providers.JsonRpcProvider({
url: NEAR_TEST_CHAINS[chainId as TNearChain].rpc
})
const signedTxs = await this.signTransactions({ chainId, topic, transactions })
const results: Array<providers.FinalExecutionOutcome> = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export async function approveNearRequest(
const [signedTx] = await nearWallet.signTransactions({
chainId,
topic,
transactions: [transactions.Transaction.decode(Buffer.from(request.params.transaction))]
transactions: [
transactions.Transaction.decode(
Buffer.from(Object.values(request.params.transaction as object))
)
]
})

return formatJsonRpcResult(id, signedTx.encode())
Expand Down Expand Up @@ -107,7 +111,7 @@ export async function approveNearRequest(
chainId,
topic,
transactions: params.request.params.transactions.map((tx: Uint8Array) => {
return transactions.Transaction.decode(Buffer.from(tx))
return transactions.Transaction.decode(Buffer.from(Object.values(tx)))
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function SessionSignNearModal() {
const { request, chainId } = params

const formatTransaction = (transaction: Uint8Array) => {
const tx = transactions.Transaction.decode(Buffer.from(transaction))
const tx = transactions.Transaction.decode(Buffer.from(Object.values(transaction)))

return {
signerId: tx.signerId,
Expand All @@ -49,7 +49,7 @@ export default function SessionSignNearModal() {
type: 'DeployContract',
params: {
...action.deployContract,
args: Buffer.from(action.deployContract.code).toString()
args: Buffer.from(action.deployContract!.code).toString()
}
}
}
Expand All @@ -58,7 +58,7 @@ export default function SessionSignNearModal() {
type: 'FunctionCall',
params: {
...action.functionCall,
args: JSON.parse(Buffer.from(action.functionCall.args).toString())
args: JSON.parse(Buffer.from(action.functionCall!.args).toString())
}
}
}
Expand All @@ -73,7 +73,7 @@ export default function SessionSignNearModal() {
type: 'Stake',
params: {
...action.stake,
publicKey: action.stake.publicKey.toString()
publicKey: action.stake!.publicKey.toString()
}
}
}
Expand All @@ -82,7 +82,7 @@ export default function SessionSignNearModal() {
type: 'AddKey',
params: {
...action.addKey,
publicKey: action.addKey.publicKey.toString()
publicKey: action.addKey!.publicKey.toString()
}
}
}
Expand All @@ -91,7 +91,7 @@ export default function SessionSignNearModal() {
type: 'DeleteKey',
params: {
...action.deleteKey,
publicKey: action.deleteKey.publicKey.toString()
publicKey: action.deleteKey!.publicKey.toString()
}
}
}
Expand Down

0 comments on commit be30acc

Please sign in to comment.