Skip to content

Commit

Permalink
Change to generate webwalletparameters with ccd-js-gen tool
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Mar 7, 2024
1 parent b6ae7b2 commit d8ede9a
Show file tree
Hide file tree
Showing 6 changed files with 1,357 additions and 1,299 deletions.
4 changes: 4 additions & 0 deletions sponsoredTransactionsAuction/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased changes

## 1.0.2

- Update `ccd-js-gen` tool to version "^1.2.0".

## 1.0.1

- Change `http` to `https` in the hardcoded node connection at the front end.
Expand Down
2 changes: 1 addition & 1 deletion sponsoredTransactionsAuction/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "auction-sponsored-transactions",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"engines": {
"npm": ">=10.0.0",
Expand Down
37 changes: 8 additions & 29 deletions sponsoredTransactionsAuction/frontend/src/auction_contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as AuctionContract from '../generated/sponsored_tx_enabled_auction_spon

import {
AccountTransactionType,
toBuffer,
UpdateContractPayload,
CcdAmount,
ReceiveName,
Expand All @@ -13,17 +12,8 @@ import {
ContractAddress,
ConcordiumGRPCWebClient,
} from '@concordium/web-sdk';
import {
ADD_ITEM_PARAMETER_SCHEMA,
AUCTION_CONTRACT_NAME,
AUCTION_END,
AUCTION_START,
CONTRACT_SUB_INDEX,
EPSILON_ENERGY,
NODE,
PORT,
} from './constants';
import { TypedSmartContractParameters, WalletConnection } from '@concordium/wallet-connectors';
import { AUCTION_CONTRACT_NAME, CONTRACT_SUB_INDEX, EPSILON_ENERGY, NODE, PORT } from './constants';
import { WalletConnection } from '@concordium/wallet-connectors';

import JSONbig from 'json-bigint';

Expand Down Expand Up @@ -73,24 +63,13 @@ export async function addItem(
maxContractExecutionEnergy,
};

// The `ccd-js-gen` tool is not fully integrated with the browser wallet yet and we need
// to manually convert from Cis2MultiContract.AddItemParameter to TypedSmartContractParameters.
const params: TypedSmartContractParameters = {
parameters: {
end: AUCTION_END, // Hardcoded value for simplicity for this demo dApp.
start: AUCTION_START, // Hardcoded value for simplicity for this demo dApp.
minimum_bid: addItemParameter.minimum_bid.toString(),
name: addItemParameter.name,
token_id: addItemParameter.token_id,
},
schema: {
type: 'TypeSchema',
value: toBuffer(ADD_ITEM_PARAMETER_SCHEMA, 'base64'),
},
};

return connection
.signAndSendTransaction(AccountAddress.toBase58(accountAddress), AccountTransactionType.Update, payload, params)
.signAndSendTransaction(
AccountAddress.toBase58(accountAddress),
AccountTransactionType.Update,
payload,
AuctionContract.createAddItemParameterWebWallet(addItemParameter),
)
.then(TransactionHash.fromHexString);
}

Expand Down
52 changes: 10 additions & 42 deletions sponsoredTransactionsAuction/frontend/src/cis2_token_contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Cis2MultiContract from '../generated/cis2_multi_cis2_multi'; // Code

import {
AccountTransactionType,
toBuffer,
UpdateContractPayload,
CcdAmount,
ReceiveName,
Expand All @@ -13,16 +12,8 @@ import {
ContractAddress,
ConcordiumGRPCWebClient,
} from '@concordium/web-sdk';
import {
CONTRACT_SUB_INDEX,
EPSILON_ENERGY,
METADATA_URL,
MINT_PARAMETER_SCHEMA,
NODE,
PORT,
SPONSORED_TX_CONTRACT_NAME,
} from './constants';
import { TypedSmartContractParameters, WalletConnection } from '@concordium/wallet-connectors';
import { CONTRACT_SUB_INDEX, EPSILON_ENERGY, NODE, PORT, SPONSORED_TX_CONTRACT_NAME } from './constants';
import { WalletConnection } from '@concordium/wallet-connectors';

import JSONbig from 'json-bigint';

Expand Down Expand Up @@ -72,37 +63,14 @@ export async function mint(
maxContractExecutionEnergy,
};

if (mintParameter.owner.type == 'Account') {
// The `ccd-js-gen` tool is not fully integrated with the browser wallet yet and we need
// to manually convert from Cis2MultiContract.MintParameter to TypedSmartContractParameters.
const params: TypedSmartContractParameters = {
parameters: {
owner: { Account: [mintParameter.owner.content.address] },
metadata_url: {
hash: {
None: [],
},
url: METADATA_URL, // In production, you should consider using a different metadata file for each token_id.
},
token_id: mintParameter.token_id,
},
schema: {
type: 'TypeSchema',
value: toBuffer(MINT_PARAMETER_SCHEMA, 'base64'),
},
};

return connection
.signAndSendTransaction(
AccountAddress.toBase58(accountAddress),
AccountTransactionType.Update,
payload,
params,
)
.then(TransactionHash.fromHexString);
} else {
throw new Error('MintParameter.owner.type should be an Account.');
}
return connection
.signAndSendTransaction(
AccountAddress.toBase58(accountAddress),
AccountTransactionType.Update,
payload,
Cis2MultiContract.createMintParameterWebWallet(mintParameter),
)
.then(TransactionHash.fromHexString);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions sponsoredTransactionsAuction/frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,4 @@ export const SERIALIZATION_HELPER_SCHEMA_PERMIT_MESSAGE =

export const SERIALIZATION_HELPER_SCHEMA_ADDITIONAL_DATA = 'Aw==';

export const MINT_PARAMETER_SCHEMA =
'FAADAAAABQAAAG93bmVyFQIAAAAHAAAAQWNjb3VudAEBAAAACwgAAABDb250cmFjdAEBAAAADAwAAABtZXRhZGF0YV91cmwUAAIAAAADAAAAdXJsFgEEAAAAaGFzaBUCAAAABAAAAE5vbmUCBAAAAFNvbWUBAQAAAB4gAAAACAAAAHRva2VuX2lkHQA=';

export const ADD_ITEM_PARAMETER_SCHEMA =
'FAAFAAAABAAAAG5hbWUWAgMAAABlbmQNBQAAAHN0YXJ0DQsAAABtaW5pbXVtX2JpZBslAAAACAAAAHRva2VuX2lkHQA=';

export const BROWSER_WALLET = ephemeralConnectorType(BrowserWalletConnector.create);
Loading

0 comments on commit d8ede9a

Please sign in to comment.