Skip to content

Commit

Permalink
Use new transaction fromJSON and toJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
lassemoldrup committed Dec 13, 2023
1 parent 2417d33 commit 76ef300
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/add-example-Web3Id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "live-server ./index.html --mount=/sdk.js:../../node_modules/@concordium/web-sdk/lib/concordium.min.js --mount=/helpers.js:../../packages/browser-wallet-api-helpers/lib/concordiumHelpers.min.js"
},
"dependencies": {
"@concordium/web-sdk": "^7.1.0"
"@concordium/web-sdk": "alpha"
}
}
2 changes: 1 addition & 1 deletion examples/eSealing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.4.0",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"@thi.ng/leb128": "^2.1.18",
"@types/sha256": "^0.2.0",
"@walletconnect/types": "^2.1.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-minting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"cors": "^2.8.5",
"express": "^4.18.1",
"express-fileupload": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/piggybank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"react": "^18.1.0",
"react-dom": "^18.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/two-step-transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "live-server ../two-step-transfer/index.html --mount=/sdk.js:../../node_modules/@concordium/web-sdk/lib/min/concordium.web.min.js --mount=/helpers.js:../../packages/browser-wallet-api-helpers/lib/concordiumHelpers.min.js"
},
"dependencies": {
"@concordium/web-sdk": "^7.1.0"
"@concordium/web-sdk": "alpha"
}
}
2 changes: 1 addition & 1 deletion examples/voting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "^3.0.0",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"bootstrap": "^5.2.1",
"moment": "^2.29.4",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/wCCD/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.4.0",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"@thi.ng/leb128": "^2.1.18",
"@walletconnect/types": "^2.1.4",
"mathjs": "^11.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-wallet-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/browser-wallet-message-hub": "workspace:^",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"@concordium/web-sdk-legacy": "npm:@concordium/web-sdk@6",
"@protobuf-ts/grpcweb-transport": "^2.8.2",
"@protobuf-ts/runtime-rpc": "^2.8.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-wallet-api/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { CcdAmount, jsonStringify } from '@concordium/web-sdk/types';
import { CcdAmount } from '@concordium/web-sdk/types';
import { Buffer } from 'buffer/';
import { isGtuAmount } from './compatibility';
import { serializationTypes } from './constants';
Expand Down Expand Up @@ -29,5 +29,5 @@ export function replacer(this: any, k: string, value: any) {
* Stringify that acts as an inverse for parse from browser-wallet @shared/utils/payload-helpers
*/
export function stringify(input: any) {
return jsonStringify(input, replacer);
return JSON.stringify(input, replacer);
}
28 changes: 27 additions & 1 deletion packages/browser-wallet-api/src/wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
SchemaVersion,
ContractAddress,
VerifiablePresentation,
getAccountTransactionHandler,
AccountTransactionPayload,
Parameter,
} from '@concordium/web-sdk/types';
import {
WalletApi as IWalletApi,
Expand All @@ -24,6 +27,8 @@ import {
AccountAddressSource,
SchemaSource,
SendTransactionPayload,
SendTransactionUpdateContractPayload,
SendTransactionInitContractPayload,
} from '@concordium/browser-wallet-api-helpers';
import EventEmitter from 'events';
import { IdProofOutput, IdStatement } from '@concordium/web-sdk/id';
Expand Down Expand Up @@ -132,12 +137,33 @@ class WalletApi extends EventEmitter implements IWalletApi {
schemaVersion?: SchemaVersion
): Promise<string> {
const input = sanitizeSendTransactionInput(accountAddress, type, payload, parameters, schema, schemaVersion);

let accountTransactionPayload: AccountTransactionPayload;
switch (type) {
case AccountTransactionType.Update:
accountTransactionPayload = {
...(payload as SendTransactionUpdateContractPayload),
message: Parameter.empty(),
};
break;
case AccountTransactionType.InitContract:
accountTransactionPayload = {
...(payload as SendTransactionInitContractPayload),
param: Parameter.empty(),
};
break;
default:
accountTransactionPayload = payload as AccountTransactionPayload;
break;
}

const handler = getAccountTransactionHandler(type);
const response = await this.messageHandler.sendMessage<MessageStatusWrapper<string>>(
MessageType.SendTransaction,
{
...input,
accountAddress: AccountAddress.toBase58(input.accountAddress),
payload: stringify(input.payload),
payload: stringify(handler.toJSON(accountTransactionPayload)),
}
);

Expand Down
2 changes: 1 addition & 1 deletion packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@concordium/browser-wallet-api": "workspace:^",
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/browser-wallet-message-hub": "workspace:^",
"@concordium/web-sdk": "^7.1.0",
"@concordium/web-sdk": "alpha",
"@noble/ed25519": "^1.7.0",
"@protobuf-ts/runtime-rpc": "^2.8.2",
"@scure/bip39": "^1.1.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/browser-wallet/src/shared/utils/payload-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EntrypointName,
Parameter,
jsonParse,
getAccountTransactionHandler,
} from '@concordium/web-sdk';
import { Buffer } from 'buffer/';
import { SmartContractParameters, SchemaType, SchemaWithContext } from '@concordium/browser-wallet-api-helpers';
Expand Down Expand Up @@ -60,7 +61,9 @@ export function parsePayload(
schema?: SchemaWithContext,
schemaVersion: SchemaVersion = 0
): HeadlessTransaction {
const payload = parse(stringifiedPayload);
const payloadJSON = parse(stringifiedPayload);
const handler = getAccountTransactionHandler(type);
const payload = handler.fromJSON(payloadJSON);

switch (type) {
case AccountTransactionType.Update: {
Expand Down Expand Up @@ -116,6 +119,11 @@ export function parsePayload(
},
};
}
case AccountTransactionType.Transfer:
return {
type,
payload: payload as SimpleTransferPayload,
};
default:
return {
type,
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ __metadata:
dependencies:
"@concordium/browser-wallet-api-helpers": "workspace:^"
"@concordium/browser-wallet-message-hub": "workspace:^"
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@concordium/web-sdk-legacy": "npm:@concordium/web-sdk@6"
"@protobuf-ts/grpcweb-transport": ^2.8.2
"@protobuf-ts/runtime-rpc": ^2.8.2
Expand Down Expand Up @@ -2213,7 +2213,7 @@ __metadata:
"@concordium/browser-wallet-api": "workspace:^"
"@concordium/browser-wallet-api-helpers": "workspace:^"
"@concordium/browser-wallet-message-hub": "workspace:^"
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@craftamap/esbuild-plugin-html": ^0.4.0
"@mdx-js/react": ^1.6.22
"@noble/ed25519": ^1.7.0
Expand Down Expand Up @@ -2358,9 +2358,9 @@ __metadata:
languageName: node
linkType: hard

"@concordium/web-sdk@npm:^7.1.0":
version: 7.1.0
resolution: "@concordium/web-sdk@npm:7.1.0"
"@concordium/web-sdk@npm:alpha":
version: 7.2.0-rc.1
resolution: "@concordium/web-sdk@npm:7.2.0-rc.1"
dependencies:
"@concordium/rust-bindings": 2.0.1
"@grpc/grpc-js": ^1.9.4
Expand All @@ -2378,7 +2378,7 @@ __metadata:
iso-3166-1: ^2.1.1
json-bigint: ^1.0.0
uuid: ^8.3.2
checksum: 471518fee52c45fc9bc826c4025f7da890c51a02cffaaaeab22c4b4eea0848c0ef47164719fa0c4053335c40c1e37dab323cc40c59b5b09e37790088caf517a5
checksum: e6d92a20a8c28d9ed6542ea1646ee1c03a2b17a8e498bf67de9b5cf08927a5d4a39f3c404f6b8fe2e3eb89727f5d8630c9d035d5da4c0445324968cdf8ab91f7
languageName: node
linkType: hard

Expand Down Expand Up @@ -7529,7 +7529,7 @@ __metadata:
resolution: "NFT-Minting@workspace:examples/nft-minting"
dependencies:
"@concordium/browser-wallet-api-helpers": "workspace:^"
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@craftamap/esbuild-plugin-html": ^0.4.0
"@types/react": ^18.0.9
"@types/react-dom": ^18.0.5
Expand Down Expand Up @@ -7681,7 +7681,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "add-example-web3-id@workspace:examples/add-example-Web3Id"
dependencies:
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
live-server: ^1.2.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -11075,7 +11075,7 @@ __metadata:
resolution: "e_sealing@workspace:examples/eSealing"
dependencies:
"@concordium/react-components": ^0.4.0
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@thi.ng/leb128": ^2.1.18
"@types/node": ^18.7.23
"@types/react": ^18.0.9
Expand Down Expand Up @@ -18359,7 +18359,7 @@ __metadata:
resolution: "piggybank@workspace:examples/piggybank"
dependencies:
"@concordium/browser-wallet-api-helpers": "workspace:^"
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@types/react": ^18.0.9
"@types/react-dom": ^18.0.5
"@vitejs/plugin-react-swc": ^3.4.0
Expand Down Expand Up @@ -22465,7 +22465,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "two-step-transfer@workspace:examples/two-step-transfer"
dependencies:
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
live-server: ^1.2.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -23241,7 +23241,7 @@ __metadata:
resolution: "voting@workspace:examples/voting"
dependencies:
"@concordium/browser-wallet-api-helpers": ^3.0.0
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@types/node": ^18.7.23
"@types/react": ^18.0.9
"@types/react-dom": ^18.0.5
Expand Down Expand Up @@ -23365,7 +23365,7 @@ __metadata:
resolution: "wccd@workspace:examples/wCCD"
dependencies:
"@concordium/react-components": ^0.4.0
"@concordium/web-sdk": ^7.1.0
"@concordium/web-sdk": alpha
"@thi.ng/leb128": ^2.1.18
"@types/node": ^18.7.23
"@types/react": ^18.0.9
Expand Down

0 comments on commit 76ef300

Please sign in to comment.