Skip to content

Commit

Permalink
Remove usage of instanceof when sanitizing wallet-api inputs + use Ac…
Browse files Browse the repository at this point in the history
…countAddress in piggybank
  • Loading branch information
Hjort committed Nov 7, 2023
1 parent 48495f4 commit ce9d379
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions examples/piggybank/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
InitName,
ReceiveName,
UpdateContractPayload,
AccountAddress,
} from '@concordium/web-sdk';

export const CONTRACT_NAME = 'PiggyBank';
Expand All @@ -26,7 +27,7 @@ export const deposit = (account: string, index: bigint, subindex = 0n, amount =
detectConcordiumProvider()
.then((provider) => {
provider
.sendTransaction(account, AccountTransactionType.Update, {
.sendTransaction(AccountAddress.fromBase58(account), AccountTransactionType.Update, {
amount: CcdAmount.fromMicroCcd(amount),
address: ContractAddress.create(index, subindex),
receiveName: ReceiveName.fromString(`${CONTRACT_NAME}.insert`),
Expand All @@ -50,7 +51,7 @@ export const smash = (account: string, index: bigint, subindex = 0n) => {
detectConcordiumProvider()
.then((provider) => {
provider
.sendTransaction(account, AccountTransactionType.Update, {
.sendTransaction(AccountAddress.fromBase58(account), AccountTransactionType.Update, {
amount: CcdAmount.fromMicroCcd(0), // This feels weird? Why do I need an amount for a non-payable receive?
address: ContractAddress.create(index, subindex),
receiveName: ReceiveName.fromString(`${CONTRACT_NAME}.smash`),
Expand Down
10 changes: 6 additions & 4 deletions packages/browser-wallet-api/src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function isGtuAmount(cand: any): cand is GtuAmount {
}

function sanitizeAccountAddress(accountAddress: AccountAddressSource): AccountAddress.Type {
return AccountAddress.instanceOf(accountAddress) ? accountAddress : AccountAddress.fromBase58(accountAddress);
return typeof accountAddress === 'string'
? AccountAddress.fromBase58(accountAddress)
: AccountAddress.fromBase58(accountAddress.address);
}

export type SanitizedSignMessageInput = {
Expand Down Expand Up @@ -92,10 +94,10 @@ export function sanitizeAddCIS2TokensInput(
): SanitizedAddCIS2TokensInput {
const accountAddress = sanitizeAccountAddress(_accountAddress);
let contractAddress: ContractAddress.Type;
if (ContractAddress.instanceOf(contractAddressSource)) {
contractAddress = contractAddressSource;
} else {
if (typeof contractAddressSource === 'bigint') {
contractAddress = ContractAddress.create(contractAddressSource, contractSubindex);
} else {
contractAddress = ContractAddress.create(contractAddressSource.index, contractSubindex);
}

return { accountAddress, tokenIds, contractAddress };
Expand Down
1 change: 1 addition & 0 deletions packages/browser-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Sign message's stringification failing with new `deserializeTypeValue`.
- An issue where the max contract execution energy was not rendered correctly for init contract transactions.
- Updated web-sdk to fix an issue where init contract transactions were not serialized correctly.
- Errors in wallet-api from version mismatch between wallet and dApps.

## 1.1.10

Expand Down

0 comments on commit ce9d379

Please sign in to comment.