Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutation keys #121

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/wagemos-cosmoskit-nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# wagemos-cosmoskit-nextjs

## 0.3.16

### Patch Changes

- Updated dependencies [[`4084d7a`](https://github.com/AbstractSDK/abstract.js/commit/4084d7a33f751883c8fa83898007edefa4a5a2ff)]:
- @abstract-money/react@1.3.3
- @abstract-money/provider-cosmoskit@5.0.3

## 0.3.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-cosmoskit-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wagemos-cosmoskit-nextjs",
"version": "0.3.15",
"version": "0.3.16",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
8 changes: 8 additions & 0 deletions examples/wagemos-graz-nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# wagemos-graz-nextjs

## 0.3.16

### Patch Changes

- Updated dependencies [[`4084d7a`](https://github.com/AbstractSDK/abstract.js/commit/4084d7a33f751883c8fa83898007edefa4a5a2ff)]:
- @abstract-money/react@1.3.3
- @abstract-money/provider-graz@5.0.3

## 0.3.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-graz-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wagemos-graz-nextjs",
"version": "0.3.15",
"version": "0.3.16",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev",
Expand Down
7 changes: 7 additions & 0 deletions packages/provider-cosmoskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @abstract-money/provider-cosmoskit

## 5.0.3

### Patch Changes

- Updated dependencies [[`4084d7a`](https://github.com/AbstractSDK/abstract.js/commit/4084d7a33f751883c8fa83898007edefa4a5a2ff)]:
- @abstract-money/react@1.3.3

## 5.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/provider-cosmoskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abstract-money/provider-cosmoskit",
"version": "5.0.2",
"version": "5.0.3",
"description": "Provider for CosmosKit",
"homepage": "https://github.com/AbstractSDK/abstract.js#readme",
"author": "dalechyn <vlad@abstract.money>",
Expand Down
7 changes: 7 additions & 0 deletions packages/provider-graz/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @abstract-money/provider-graz

## 5.0.3

### Patch Changes

- Updated dependencies [[`4084d7a`](https://github.com/AbstractSDK/abstract.js/commit/4084d7a33f751883c8fa83898007edefa4a5a2ff)]:
- @abstract-money/react@1.3.3

## 5.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/provider-graz/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abstract-money/provider-graz",
"version": "5.0.2",
"version": "5.0.3",
"description": "Provider for Graz",
"homepage": "https://github.com/AbstractSDK/abstract.js#readme",
"author": "dalechyn <vlad@abstract.money>",
Expand Down
6 changes: 6 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @abstract-money/react

## 1.3.3

### Patch Changes

- [#121](https://github.com/AbstractSDK/abstract.js/pull/121) [`4084d7a`](https://github.com/AbstractSDK/abstract.js/commit/4084d7a33f751883c8fa83898007edefa4a5a2ff) Thanks [@adairrr](https://github.com/adairrr)! - Add mutation keys to mutations, overrideable by consumers

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abstract-money/react",
"version": "1.3.2",
"version": "1.3.3",
"description": "React Hooks for Abstract SDK",
"homepage": "https://github.com/AbstractSDK/abstract.js#readme",
"author": "dalechyn <vlad@abstract.money>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ export function useCreateRemoteAccount({
mutation,
}: UseCreateRemoteAccountParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.createRemoteAccount({ ...cosmWasmSignOptions, ...args })
}, mutation)
return useMutation(
['createRemoteAccount', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.createRemoteAccount({
...cosmWasmSignOptions,
...args,
})
},
mutation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ export function useCreateSubAccount({
mutation,
}: UseCreateSubAccountParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.createSubAccount({ ...cosmWasmSignOptions, ...args })
}, mutation)
return useMutation(
['createSubAccount', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.createSubAccount({ ...cosmWasmSignOptions, ...args })
},
mutation,
)
}
14 changes: 9 additions & 5 deletions packages/react/src/hooks/account/wallet/use-deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export function useDeposit({
DepositMutation
> {
const config = useConfig()
const accountWalletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
accountId,
chainName,
})
return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!accountWalletClient) throw new Error('client is not defined')
return accountWalletClient.deposit({ ...args, ...cosmWasmSignOptions })
}, mutation)
return useMutation(
['deposit', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('client is not defined')
return accountClient.deposit({ ...args, ...cosmWasmSignOptions })
},
mutation,
)
}
20 changes: 12 additions & 8 deletions packages/react/src/hooks/account/wallet/use-enable-ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ export function useEnableIbc({
mutation,
}: UseEnableIbcParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
if (!args.ibcEnabled) {
throw new Error('no action')
}
return useMutation(
['enableIbc', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
if (!args.ibcEnabled) {
throw new Error('no action')
}

return walletClient.enableIbc({ ...cosmWasmSignOptions, ...args })
}, mutation)
return accountClient.enableIbc({ ...cosmWasmSignOptions, ...args })
},
mutation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ export function useExecuteOnRemoteManager({
mutation,
}: UseExecuteOnRemoteManagerParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
accountId,
chainName: chainName,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.executeOnRemoteManager({
...cosmWasmSignOptions,
...args,
})
}, mutation)
return useMutation(
['executeOnRemoteManager', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.executeOnRemoteManager({
...cosmWasmSignOptions,
...args,
})
},
mutation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ export function useExecuteOnRemoteModule({
mutation,
}: UseExecuteOnRemoteModuleParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
accountId,
chainName: chainName,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.executeOnRemoteModule({
...cosmWasmSignOptions,
...args,
})
}, mutation)
return useMutation(
['executeOnRemoteModule', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.executeOnRemoteModule({
...cosmWasmSignOptions,
...args,
})
},
mutation,
)
}
14 changes: 9 additions & 5 deletions packages/react/src/hooks/account/wallet/use-execute-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export function useExecuteRemote({
mutation,
}: UseExecuteRemoteParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
accountId,
chainName: chainName,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.executeRemote({ ...cosmWasmSignOptions, ...args })
}, mutation)
return useMutation(
['executeRemote', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.executeRemote({ ...cosmWasmSignOptions, ...args })
},
mutation,
)
}
14 changes: 9 additions & 5 deletions packages/react/src/hooks/account/wallet/use-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ export function useExecute({
ExecuteMutation
> {
const config = useConfig()
const accountWalletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})
return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!accountWalletClient) throw new Error('client is not defined')
return accountWalletClient.execute({ ...cosmWasmSignOptions, ...args })
}, mutation)
return useMutation(
['execute', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('client is not defined')
return accountClient.execute({ ...cosmWasmSignOptions, ...args })
},
mutation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ export function useRequestRemoteFunds({
mutation,
}: UseRequestRemoteFundsParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.requestFundsFromRemote({
...cosmWasmSignOptions,
...args,
})
}, mutation)
return useMutation(
['requestRemoteFunds', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.requestFundsFromRemote({
...cosmWasmSignOptions,
...args,
})
},
mutation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ export function useUseSendFundsToRemote({
mutation,
}: UseSendFundsToRemoteParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
const accountClient = config.useAccountWalletClient({
chainName,
accountId,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.sendFundsToRemote({ ...cosmWasmSignOptions, ...args })
}, mutation)
return useMutation(
['sendFundsToRemote', chainName, accountId],
({ args, ...cosmWasmSignOptions }) => {
if (!accountClient) throw new Error('accountClient is not defined')
return accountClient.sendFundsToRemote({
...cosmWasmSignOptions,
...args,
})
},
mutation,
)
}
10 changes: 7 additions & 3 deletions packages/react/src/hooks/account/wallet/use-update-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export function useUpdateSettings({
mutation,
})

return useMutation(async ({ args, ...cosmWasmSignOptions }) => {
return await mutateAsync({ ...cosmWasmSignOptions, args })
}, mutation)
return useMutation(
['updateSettings', chainName, accountId],
async ({ args, ...cosmWasmSignOptions }) => {
return await mutateAsync({ ...cosmWasmSignOptions, args })
},
mutation,
)
}
Loading
Loading