From f7bd15eb950d113c97686b1297380e56ec9ae419 Mon Sep 17 00:00:00 2001 From: Georgi Tsonev Date: Wed, 24 Jul 2024 14:05:55 +0300 Subject: [PATCH 1/3] fix near-mobile-wallet, near-snap and ramper-wallet methods --- packages/near-mobile-wallet/src/lib/init.wallet.ts | 6 +++--- packages/near-snap/src/lib/selector.ts | 8 ++++---- packages/ramper-wallet/src/lib/ramper-wallet.ts | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/near-mobile-wallet/src/lib/init.wallet.ts b/packages/near-mobile-wallet/src/lib/init.wallet.ts index 17565d2de..19880d0f7 100644 --- a/packages/near-mobile-wallet/src/lib/init.wallet.ts +++ b/packages/near-mobile-wallet/src/lib/init.wallet.ts @@ -55,13 +55,13 @@ export const initNearMobileWallet: NearMobileWalletInit = async (config) => { async signAndSendTransaction(data) { logger.log("[NearMobileWallet]: signAndSendTransaction", data); - const { contract } = store.getState(); - if (!contract) { + const { contracts } = store.getState(); + if (contracts.length < 1) { throw new Error("Wallet not signed in"); } return await nearMobileWallet.signAndSendTransaction({ - receiverId: contract.contractId, + receiverId: contracts[0].contractId, ...data, }); }, diff --git a/packages/near-snap/src/lib/selector.ts b/packages/near-snap/src/lib/selector.ts index ba49ea261..7346f67df 100644 --- a/packages/near-snap/src/lib/selector.ts +++ b/packages/near-snap/src/lib/selector.ts @@ -44,19 +44,19 @@ export const initNearSnap: WalletBehaviourFactory = async ( async signAndSendTransaction(data) { logger.log("NearSnap:signAndSendTransaction", data); + const { contracts } = store.getState(); - if (account == null) { + if (account == null || contracts.length < 1) { throw new Error("Wallet not signed in"); } - const { contract } = store.getState(); - const receiverId = data.receiverId ?? contract?.contractId; + const receiverId = data.receiverId ?? contracts[0].contractId; if (receiverId == null) { throw new Error("ReceiverId is not defined"); } - return await account.executeTransaction({ receiverId, ...data }); + return await account.executeTransaction({ ...data, receiverId }); }, async signMessage({ message, nonce, recipient }) { diff --git a/packages/ramper-wallet/src/lib/ramper-wallet.ts b/packages/ramper-wallet/src/lib/ramper-wallet.ts index 655e3f45b..9738d8076 100644 --- a/packages/ramper-wallet/src/lib/ramper-wallet.ts +++ b/packages/ramper-wallet/src/lib/ramper-wallet.ts @@ -73,9 +73,9 @@ const RamperWallet: WalletBehaviourFactory = async ({ transactions: Array> ) => { const accounts = await getAccounts(); - const { contract } = store.getState(); + const { contracts } = store.getState(); - if (!accounts.length || !contract) { + if (!accounts.length || contracts.length < 1) { throw new Error("Wallet not signed in"); } @@ -85,7 +85,7 @@ const RamperWallet: WalletBehaviourFactory = async ({ ); return { - receiverId: transaction.receiverId || contract.contractId, + receiverId: transaction.receiverId, actions: parsedActions, }; }); @@ -127,10 +127,10 @@ const RamperWallet: WalletBehaviourFactory = async ({ }: Omit) { logger.log("signAndSendTransaction", { receiverId, actions }); - const { contract } = store.getState(); + const { contracts } = store.getState(); const accounts = await getAccounts(); - if (!accounts.length || !contract) { + if (!accounts.length || contracts.length < 1) { throw new Error("Wallet not signed in"); } From 1ff90b816a4bc89187fe323e970cec8d6c3f7000 Mon Sep 17 00:00:00 2001 From: Georgi Tsonev Date: Wed, 24 Jul 2024 17:11:13 +0300 Subject: [PATCH 2/3] fix if check --- packages/near-snap/src/lib/selector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/near-snap/src/lib/selector.ts b/packages/near-snap/src/lib/selector.ts index 7346f67df..a4113fde3 100644 --- a/packages/near-snap/src/lib/selector.ts +++ b/packages/near-snap/src/lib/selector.ts @@ -46,7 +46,7 @@ export const initNearSnap: WalletBehaviourFactory = async ( logger.log("NearSnap:signAndSendTransaction", data); const { contracts } = store.getState(); - if (account == null || contracts.length < 1) { + if (account === null || contracts.length < 1) { throw new Error("Wallet not signed in"); } From 142c44723e074fe4ef70b42bfd46d8609c1a8a0e Mon Sep 17 00:00:00 2001 From: Georgi Tsonev Date: Thu, 25 Jul 2024 13:00:59 +0300 Subject: [PATCH 3/3] update receiverId value --- packages/near-mobile-wallet/src/lib/init.wallet.ts | 2 +- packages/near-snap/src/lib/selector.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/near-mobile-wallet/src/lib/init.wallet.ts b/packages/near-mobile-wallet/src/lib/init.wallet.ts index 19880d0f7..22447dd07 100644 --- a/packages/near-mobile-wallet/src/lib/init.wallet.ts +++ b/packages/near-mobile-wallet/src/lib/init.wallet.ts @@ -61,7 +61,7 @@ export const initNearMobileWallet: NearMobileWalletInit = async (config) => { } return await nearMobileWallet.signAndSendTransaction({ - receiverId: contracts[0].contractId, + receiverId: data.receiverId, ...data, }); }, diff --git a/packages/near-snap/src/lib/selector.ts b/packages/near-snap/src/lib/selector.ts index a4113fde3..2ef409465 100644 --- a/packages/near-snap/src/lib/selector.ts +++ b/packages/near-snap/src/lib/selector.ts @@ -50,7 +50,7 @@ export const initNearSnap: WalletBehaviourFactory = async ( throw new Error("Wallet not signed in"); } - const receiverId = data.receiverId ?? contracts[0].contractId; + const receiverId = data.receiverId; if (receiverId == null) { throw new Error("ReceiverId is not defined");