Skip to content

Commit

Permalink
CU-86a0cm2j7 - Update WalletConnect to use new version of NeonInvoker…
Browse files Browse the repository at this point in the history
… to allow different wallets signing the same transaction
  • Loading branch information
endkeyCoder committed Oct 16, 2023
1 parent 5390542 commit 64f340a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/wallet-connect-sdk-core",
"comment": "Added a method for the wallet to sign a transaction",
"type": "minor"
}
],
"packageName": "@cityofzion/wallet-connect-sdk-core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/wallet-connect-sdk-wallet-core",
"comment": "Added a method for the wallet to sign a transaction",
"type": "minor"
}
],
"packageName": "@cityofzion/wallet-connect-sdk-wallet-core"
}
13 changes: 13 additions & 0 deletions e2e/tests/DappMethods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,16 @@ test('Test Calculate Fee on dapp (React)', async ({ context }) => {
expect(response.systemFee).toBeDefined() // Verify if the response returned systemFee
expect(response.total).toBeDefined() // Verify if the response returned total
})

test('Test Sign Transaction on dapp (React)', async ({ context }) => {
// Define the dapp and wallet pages
const dappPage = DAPP_REACT
const walletPage = WALLET_REACT
await connectReactDappToNewReactAccount(context, dappPage, walletPage)
await dappPage.page.waitForLoadState('networkidle') // Wait to load request
await dappPage.awaitSeconds(5) // Wait for 5 seconds
await dappPage.page.getByTestId('hello-world__sign-transaction').click() // Click on Sign Transaction button
await dappPage.awaitSeconds(2) // Wait for 2 seconds
const response = await getAnyFromInnerHTML(dappPage.page.getByTestId('hello-world__method-response'))
expect(response).toBeDefined() // Verify if the response had a return
})
30 changes: 27 additions & 3 deletions packages/wallet-connect-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Chain = "private" | "testnet" | "mainnet"

export type NetworkType = `${Blockchain}:${Chain}`

export type Method = 'invokeFunction' | 'testInvoke' | 'signMessage' | 'verifyMessage' | 'traverseIterator' | 'getWalletInfo' | "getNetworkVersion" | "encrypt" | "decrypt" | "decryptFromArray" | "calculateFee"
export type Method = 'invokeFunction' | 'testInvoke' | 'signMessage' | 'verifyMessage' | 'traverseIterator' | 'getWalletInfo' | "getNetworkVersion" | "encrypt" | "decrypt" | "decryptFromArray" | "calculateFee" | "signTransaction"

/**
* A number that will be compared by the wallet to check if it is compatible with the dApp
Expand Down Expand Up @@ -81,8 +81,32 @@ export default class WcSdk implements Neo3Invoker, Neo3Signer {
this.session = initSession
}
}
signTransaction(cim: ContractInvocationMulti | BuiltTransaction):Promise<BuiltTransaction> {
throw new Error("not implemented yet");

/**
* This method is used to sign a transaction.
* @param params the contract invocation options
* @return the call result promise
*/
async signTransaction(params: ContractInvocationMulti | BuiltTransaction): Promise<BuiltTransaction> {
this.validateContractInvocationMulti(params)
const request = {
id: 1,
jsonrpc: "2.0",
method: "signTransaction",
params
}

const resp = await this.signClient.request({
topic: this.session?.topic ?? '',
chainId: this.getChainId() ?? '',
request
})

if (!resp) {
throw new WcSdkError(resp);
}

return resp as BuiltTransaction
}

/**
Expand Down
9 changes: 8 additions & 1 deletion packages/wallet-connect-sdk-wallet-core/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
ContractInvocationMulti,
EncryptedPayload,
DecryptFromArrayResult,
CalculateFee
CalculateFee,
BuiltTransaction
} from '@cityofzion/wallet-connect-sdk-core'
export abstract class AbstractWalletConnectNeonAdapter {
protected async getServices(args: TAdapterMethodParam) {
Expand Down Expand Up @@ -127,6 +128,12 @@ export abstract class AbstractWalletConnectNeonAdapter {
return await invoker.calculateFee(params)
}

async signTransaction(args: TAdapterMethodParam): Promise<BuiltTransaction> {
const {invoker} = await this.getServices(args)
const params = this.convertParams(args)
return await invoker.signTransaction(params)
}

abstract getWalletInfo(args: TAdapterMethodParam): Promise<WalletInfo>

abstract getAccountString(args: TAdapterMethodParam): Promise<string>
Expand Down

0 comments on commit 64f340a

Please sign in to comment.