-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kyc-dev-test
- Loading branch information
Showing
191 changed files
with
2,932 additions
and
1,560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { APIError, APIHandler } from './helpers/endpoint' | ||
import { type TxnData, insertTxns } from 'shared/txn/run-txn' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { incrementBalance } from 'shared/supabase/users' | ||
import { betsQueue } from 'shared/helpers/fn-queue' | ||
import { CASH_TO_MANA_CONVERSION_RATE } from 'common/envs/constants' | ||
import { calculateRedeemablePrizeCash } from 'shared/calculate-redeemable-prize-cash' | ||
|
||
export const convertCashToMana: APIHandler<'convert-cash-to-mana'> = async ( | ||
{ amount }, | ||
auth | ||
) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
await betsQueue.enqueueFn(async () => { | ||
// check if user has enough cash | ||
await pg.tx(async (tx) => { | ||
const redeemable = await calculateRedeemablePrizeCash(auth.uid, tx) | ||
if (redeemable < amount) { | ||
throw new APIError(403, 'Not enough redeemable balance') | ||
} | ||
|
||
await incrementBalance(tx, auth.uid, { | ||
cashBalance: -amount, | ||
balance: amount * CASH_TO_MANA_CONVERSION_RATE, | ||
}) | ||
}) | ||
|
||
// key for equivalence | ||
const insertTime = Date.now() | ||
|
||
const toBank: TxnData = { | ||
category: 'CONVERT_CASH', | ||
fromType: 'USER', | ||
fromId: auth.uid, | ||
toType: 'BANK', | ||
toId: 'BANK', | ||
amount: amount, | ||
token: 'SPICE', | ||
description: 'Convert cash to mana', | ||
data: { insertTime }, | ||
} | ||
|
||
const toYou: TxnData = { | ||
category: 'CONVERT_CASH_DONE', | ||
fromType: 'BANK', | ||
fromId: 'BANK', | ||
toType: 'USER', | ||
toId: auth.uid, | ||
amount: amount, | ||
token: 'M$', | ||
description: 'Convert cash to mana', | ||
data: { | ||
insertTime, | ||
}, | ||
} | ||
|
||
await pg.tx((tx) => insertTxns(tx, [toBank, toYou])) | ||
}, [auth.uid]) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { getManaSupply as fetchManaSupply } from 'shared/mana-supply' | ||
import { APIHandler } from './helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const getManaSupply: APIHandler<'get-mana-supply'> = async () => { | ||
return await fetchManaSupply(false) | ||
const pg = createSupabaseDirectClient() | ||
return await fetchManaSupply(pg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.