Skip to content

Commit

Permalink
🔄 synced local 'src/' with remote 'src/'
Browse files Browse the repository at this point in the history
  • Loading branch information
circle-github-action-bot committed Jun 26, 2024
1 parent 9489b80 commit 00b9209
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/controllers/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { NextFunction, Request, Response } from 'express';
import { circleUserSdk } from '../services';
import { Blockchain } from '@circle-fin/user-controlled-wallets';

export const dripFaucet = async (
req: Request,
Expand All @@ -26,7 +27,8 @@ export const dripFaucet = async (
await circleUserSdk.requestTestnetTokens({
address: req.body.address,
blockchain: req.body.blockchain,
usdc: true
usdc: true,
native: req.body.blockchain === Blockchain.AvaxFuji
});

res.status(200).send();
Expand Down
18 changes: 18 additions & 0 deletions src/controllers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Blockchain } from '@circle-fin/user-controlled-wallets';
import { circleUserSdk } from '../services';
import { Request, Response, NextFunction } from 'express';

Expand Down Expand Up @@ -67,3 +68,20 @@ export const getWallet = async (
next(error);
}
};

export const createWallet = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const response = await circleUserSdk.createWallet({
blockchains: [req.body.blockchain as Blockchain],
userToken: req.headers['token'] as string
});

res.status(200).send(response.data?.challengeId);
} catch (error: unknown) {
next(error);
}
};
35 changes: 34 additions & 1 deletion src/routers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import {
validate,
walletTokenBalanceSchema
} from '../middleware';
import { getWallet, getWalletTokenBalance, listWallets } from '../controllers';
import {
createWallet,
getWallet,
getWalletTokenBalance,
listWallets
} from '../controllers';

import * as yup from 'yup';

const wallets = express.Router();

Expand Down Expand Up @@ -122,4 +129,30 @@ wallets.get(
*/
wallets.get('/:id', validate(getWalletSchema), getWallet);

/**
* POST - /wallets
* Creates a user controlled wallet with given blockchain.
*
* Body:
* blockchain: Blockchain - Blockchain network to create wallet on
*
* Returns:
* challengeId: string - used to initiate a challenge flow for the user to create new wallet
*
*/
wallets.post(
'/',
validate(
yup.object({
body: yup
.object({
blockchain: yup.string().required()
})
.noUnknown(true)
.strict()
})
),
createWallet
);

export { wallets };

0 comments on commit 00b9209

Please sign in to comment.