Skip to content

Commit

Permalink
Merge pull request #81 from AbstractSDK/refactor/core-and-react
Browse files Browse the repository at this point in the history
feat!: api changes to `core` and `react` packages
  • Loading branch information
dalechyn authored Mar 14, 2024
2 parents 48cdc3b + 427df38 commit 6b5fbf4
Show file tree
Hide file tree
Showing 119 changed files with 2,052 additions and 1,568 deletions.
9 changes: 9 additions & 0 deletions .changeset/strange-clocks-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@abstract-money/core": major
"@abstract-money/react": major
"wagemos-cosmoskit-nextjs": patch
"wagemos-graz-nextjs": patch
"@abstract-money/cli": patch
---

Changed the API for `react` and `core` packages. Previously `core` package had unnecessary `args:{}` wrapping, now it doesn't. Also, `query` and `mutation` fields were added to the `react` package to have a clear separation of concerns, as well as fixed inconsistent API around `chainName` and types.
84 changes: 36 additions & 48 deletions examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -128,14 +126,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -192,14 +188,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -255,14 +249,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -320,14 +312,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -383,14 +373,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down
84 changes: 36 additions & 48 deletions examples/wagemos-graz-nextjs/src/_generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -128,14 +126,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -192,14 +188,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -255,14 +249,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -320,14 +312,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down Expand Up @@ -383,14 +373,12 @@ export const betting = {
isLoading: isBettingAppQueryClientLoading,
isError: isBettingAppQueryClientError,
error: bettingAppQueryClientError,
} = useAbstractModuleQueryClient(
{
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
},
{ enabled: options?.enabled },
)
} = useAbstractModuleQueryClient({
moduleId: BETTING_MODULE_ID,
...rest,
Module: BettingAppQueryClient,
query: { enabled: options?.enabled },
})

const {
data,
Expand Down
20 changes: 8 additions & 12 deletions examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export default function AuthzPage() {
const { data: account } = useAccount({ chainId: 'osmosis-1' })

const { data: accountFactory, isLoading } =
useAccountFactoryQueryClientFromApi(CHAIN_NAME)
useAccountFactoryQueryClientFromApi({ chainName: CHAIN_NAME, args: {} })

const { mutate: createAccount } = useCreateAccountMonarchy({
args: { chainName: CHAIN_NAME },
chainName: CHAIN_NAME,
})

const onCreateAccount = useCallback(async () => {
Expand All @@ -59,17 +59,13 @@ export default function AuthzPage() {
})
}, [accountFactory])

const { data: savingsAppAddress } = useModuleInstantiate2AddressFromApi(
{
accountId: stringToAccountId(TEST_SAVINGS_ACCOUNT_ID, CHAIN_NAME),
args: {
moduleId: SAVINGS_APP_MODULE_ID,
},
const { data: savingsAppAddress } = useModuleInstantiate2AddressFromApi({
accountId: stringToAccountId(TEST_SAVINGS_ACCOUNT_ID, CHAIN_NAME),
args: {
moduleId: SAVINGS_APP_MODULE_ID,
},
{
enabled: true,
},
)
query: { enabled: true },
})

console.log('calculated savings app address', savingsAppAddress)

Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/plugins/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ export function react(options: ReactOptions = {}): ReactResult {
}
...rest,
Module: ${queryClientPascalCase},
${
hasAbstractApp
? 'query: { enabled: options?.enabled }'
: ''
}
},
${hasAbstractApp ? '{ enabled: options?.enabled }' : ''}
)
const {
Expand Down
1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file. Do not edit directly.
actions/**
clients/**
utils/**
legacy/**
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./actions": {
"types": "./dist/actions/index.d.ts",
"default": "./dist/actions/index.js"
},
"./clients": {
"types": "./dist/clients/index.d.ts",
"default": "./dist/clients/index.js"
Expand All @@ -94,6 +98,7 @@
"./package.json": "./package.json"
},
"files": [
"/actions",
"/clients",
"/utils",
"/legacy",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { VersionControlTypes } from '../../../codegen/abstract'
import { WithArgs } from '../../../types/with-args'
import { accountIdToParameter } from '../../../utils/account-id'
import { getVersionControlQueryClientFromApi } from '../../public/get-version-control-query-client-from-api'

export type GetAccountBaseAddressesFromApiParameters = WithArgs<{
export type GetAccountBaseAddressesFromApiParameters = {
accountId: VersionControlTypes.AccountId
cosmWasmClient: CosmWasmClient
apiUrl: string
}>
}

export async function getAccountBaseAddressesFromApi({
args: { accountId, cosmWasmClient, apiUrl },
accountId,
cosmWasmClient,
apiUrl,
}: GetAccountBaseAddressesFromApiParameters) {
const versionControlQueryClient = await getVersionControlQueryClientFromApi({
args: {
cosmWasmClient,
apiUrl,
},
cosmWasmClient,
apiUrl,
})
const { account_base: accountBase } =
await versionControlQueryClient.accountBase({
Expand Down
Loading

0 comments on commit 6b5fbf4

Please sign in to comment.