Skip to content

Commit

Permalink
Make sure walletProvider returns on user accounts in /check-secondary…
Browse files Browse the repository at this point in the history
…-address
  • Loading branch information
ccali11 committed May 17, 2023
1 parent 088c66c commit a6fb5d7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/web/src/composables/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export default function useWallet() {
}

const accountsIfSecondaryAddress : Account[] | void = await checkIfSecondaryAddress(selectedAddress.value)
console.log('accountsIfSecondaryAddress :>> ', accountsIfSecondaryAddress)
if (accountsIfSecondaryAddress.length) {
return accountsIfSecondaryAddress
} else {
Expand Down
7 changes: 6 additions & 1 deletion common/data/src/schemas/user.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
"updated_at": {
"type": "string",
"description": "The account last update date in ISO 8601 format"
},
"wallet_provider": {
"type": "string",
"description": "The wallet provider used set a primary user account"
}
},
"required": [
"address",
"created_at",
"id",
"updated_at"
"updated_at",
"wallet_provider"
]
}
4 changes: 4 additions & 0 deletions common/types/src/interfaces/User.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ProviderString } from '@casimir/types'

export interface User {
/** Unique ID (and essential for auth verification) */
address: string
Expand All @@ -7,4 +9,6 @@ export interface User {
id: number
/* ISO Timestamp of when user was last updated */
updatedAt?: string
/** Wallet provider (e.g. metamask) */
walletProvider: ProviderString
}
6 changes: 3 additions & 3 deletions services/users/src/providers/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export default function useDB() {
* @returns The new user
*/
async function addUser(user: User, account: Account) : Promise<UserAddedSuccess | undefined> {
const { address, createdAt, updatedAt } = user
const text = 'INSERT INTO users (address, created_at, updated_at) VALUES ($1, $2, $3) RETURNING *;'
const params = [address, createdAt, updatedAt]
const { address, createdAt, updatedAt, walletProvider } = user
const text = 'INSERT INTO users (address, created_at, updated_at, wallet_provider) VALUES ($1, $2, $3, $4) RETURNING *;'
const params = [address, createdAt, updatedAt, walletProvider]
const rows = await postgres.query(text, params)
const addedUser = rows[0]
account.userId = addedUser.id
Expand Down
9 changes: 6 additions & 3 deletions services/users/src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ router.post('/login', async (req: express.Request, res: express.Response) => {
address,
createdAt: now,
updatedAt: now,
walletProvider: provider,
} as User
const account = {
address,
Expand Down Expand Up @@ -107,9 +108,11 @@ router.post('/check-secondary-address', async (req: express.Request, res: expres
const users = await Promise.all(accounts.map(async account => {
const { userId } = account
const user = await getUserById(userId)
// TODO: Update users schema to include walletProvider
const { address } = user
return { address: maskAddress(address) }
const { address, walletProvider } = user
return {
address: maskAddress(address),
walletProvider,
}
}))
res.setHeader('Content-Type', 'application/json')
res.status(200)
Expand Down

0 comments on commit a6fb5d7

Please sign in to comment.