Skip to content

Commit

Permalink
Merge branch 'master' into release-please--branches--master--componen…
Browse files Browse the repository at this point in the history
…ts--filsnap
  • Loading branch information
hugomrdias committed Jul 29, 2023
2 parents c35e572 + 33b8896 commit 56d8a59
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Filecoin metamask snap and related packages to enable developers to add Filecoin

## Examples

- [`demo`](./packages/demo) - Preact demo dapp using [filsnap-adapter](./packages/filsnap-adapter) to interact with [filsnap](./packages/filsnap)
- [`fil-forwarder-viem`](./packages/fil-forwarder-viem) - [Viem](https://viem.sh/) example to send FIL using FilForwarder contract.
- [`demo`](./examples/demo) - Preact demo dapp using [filsnap-adapter](./packages/filsnap-adapter) to interact with [filsnap](./packages/filsnap)
- [`fil-forwarder-viem`](./examples/fil-forwarder-viem) - [Viem](https://viem.sh/) example to send FIL using FilForwarder contract.

### Checkout examples

Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/filecoin-project/filsnap.git"
},
"source": {
"shasum": "A3iZwXzHmYbIDCPkBJ4OfiEMabYvimV54XNeqtrstNU=",
"shasum": "PrxFxKiusGgxcttw9R6UenDIU4vxcM2CFCfrX70fMWM=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ export async function configure(
method: 'snap_manageState',
params: { newState: state, operation: 'update' },
})
return { result: _params.data, error: undefined }
return { result: _params.data, error: null }
}
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/export-private-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function exportPrivateKey(
if (conf) {
return {
result: base64pad.encode(ctx.account.privateKey),
error: undefined,
error: null,
}
}
return serializeError('User denied private key export')
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/gas-for-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function getGasForMessage(
}

return {
error: undefined,
error: null,
result: {
gasFeeCap: result.GasFeeCap,
gasLimit: result.GasLimit,
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/get-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getAccountInfo(
return serializeError('RPC call to "WalletBalance" failed', balance.error)
}
return {
error: undefined,
error: null,
result: {
address: ctx.account.address.toString(),
pubKey: ctx.account.pubKey.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/get-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export async function getBalance(
if (balance.error != null) {
return serializeError('RPC call to "WalletBalance" failed', balance.error)
}
return balance
return { result: balance.result, error: null }
}
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/get-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export async function getMessages(
return serializeError(`Invalid messages in snap state`, state.error)
}

return { result: state.data.filecoin.messages, error: undefined }
return { result: state.data.filecoin.messages, error: null }
}
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/send-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export async function sendMessage(
message: params.message,
}
await updateMessageInState(snap, messageStatus)
return { result: messageStatus, error: undefined }
return { result: messageStatus, error: null }
}
4 changes: 2 additions & 2 deletions packages/snap/src/rpc/sign-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function signMessage(
if (conf) {
const sig = filSignMessage(ctx.account.privateKey, 'SECP256K1', message)
return {
error: undefined,
error: null,
result: {
message,
signature: {
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function signMessageRaw(
if (conf) {
const sig = sign(ctx.account.privateKey, 'SECP256K1', message)
return {
error: undefined,
error: null,
result: base64pad.encode(sig),
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export interface SnapError {

export interface SnapResponseError {
error: SnapError
result: undefined
result: null
}

/**
* Response from a snap request
*/
export type SnapResponse<R> =
| {
error: undefined
error: null
result: R
}
| SnapResponseError
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function serializeError(msg: string, data?: unknown): SnapResponseError {
// @ts-expect-error - no types
const _msg = (hasMessage ? _data.message : '') as string
return {
result: undefined,
result: null,
error: {
message: msg + (hasMessage ? ` - ${_msg}` : ''),
data: _data,
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/test/unit/rpc/export-seed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ describe('Test rpc handler function: exportSeed', function () {
const result = await exportPrivateKey({ snap: walletStub, account })

expect(walletStub.rpcStubs.snap_dialog).to.have.been.calledOnce()
expect(result.result).to.be.undefined()
expect(result.result).to.be.null()
})
})
12 changes: 8 additions & 4 deletions packages/snap/test/unit/rpc/get-balance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ describe('Test rpc handler function: getBalance', function () {
// prepare stubs
walletStub.prepareFoKeyPair()
const account = await getKeyPair(walletStub)
rpcStub.balance.returns('30000000')
rpcStub.balance.returns({ result: '30000000' })
// call getBalance
// @ts-expect-error - test code
const result = await getBalance({ snap: walletStub, rpc: rpcStub, account })
const balance = await getBalance({
snap: walletStub,
// @ts-expect-error - test code
rpc: rpcStub,
account,
})
// assertions
expect(walletStub.rpcStubs.snap_manageState).to.have.been.calledOnce()
expect(walletStub.rpcStubs.snap_getBip44Entropy).to.have.been.calledOnce()
expect(result).to.be.eq('30000000')
expect(balance.result).to.be.eq('30000000')
})
})
10 changes: 5 additions & 5 deletions packages/snap/test/unit/rpc/sign-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Test rpc handler function: signMessage', function () {
expect(apiStub.gasEstimate).to.have.been.calledOnce()

expect(response).to.containSubset({
error: undefined,
error: null,
result: {
message: fullMessage,
signature: {
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('Test rpc handler function: signMessage', function () {
expect(apiStub.nonce).to.have.not.been.called()

expect(response).to.containSubset({
error: undefined,
error: null,
result: {
message: {
...fullMessage,
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('Test rpc handler function: signMessage', function () {
expect(apiStub.gasEstimate).to.have.been.calledOnce()

expect(response).to.containSubset({
error: undefined,
error: null,
result: {
message: paramsMessage,
signature: {
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('Test rpc handler function: signMessage', function () {
error: {
message: 'User denied message signing',
},
result: undefined,
result: null,
})
})

Expand All @@ -243,7 +243,7 @@ describe('Test rpc handler function: signMessage', function () {
invalidMessage
)

expect(result).to.be.undefined()
expect(result).to.be.null()
expect(error).to.not.be.null()
})
})

0 comments on commit 56d8a59

Please sign in to comment.